이 문자열이 있습니다.paste0 또는 붙여 넣기가 실패하면 r에 특수 문자가 표시됩니다.
temp <- "this is Mapof ttMapof qwqqwMApofRt it"
출력으로 가져와야합니다.
"this is Mapof (Mapof) ttMapof (Mapof) qwqqwMapofRt it"
나는이 일을 오전
: (! 완벽한 아무 문제)를
temp <- gsub('Mapof\\b', 'Mapof (Mapof)', temp) #code line 1
"this is Mapof (Mapof) ttMapof (Mapof) qwqqwMapofRt it"
그러나 문제는 내가 벡터에서 '패턴'과 '교체'를 가지고 가야하기 때문에 내가 직접이 작업을 수행 할 수 없다 . '패턴'그 벡터의 '교체'를 추출 후 그래서, 나는 지금은 정확한 코드 라인 1 위 얻을하려면 다음과 같이 붙여 넣기()를 사용하고
inc_spelling <- "Mapof" #(pattern)
cor_spelling <- "Map of" #(replacement)
을 다음과 같이 보관하지만, 그것을 일어나지 않는다. 직접보십시오. 여기서 무슨 일이 일어나는거야?
txt <- paste0("temp <- gsub('",inc_spelling,"\\b','",inc_spelling," (",cor_spelling,")'"," ,temp)")
txt
"temp <- gsub('Mapof\\b','Mapof (Map of)' ,temp)"
eval(parse(text=txt))
temp
"this is Mapof ttMapof qewqeqwMapofdffd it"
실패합니다! 왜 그런가? 나는 그 버그를 알아낼 수 없다! paste()에서이 작업을 수행 할 수없는 경우 다른 대안을 제안하십시오. 감사!