以编程方式从RStudio编辑器中清除无法识别的字符(带有粉红色背景的点)

时间:2019-01-12 21:33:42

标签: r encoding editor rstudio iconv

我想从语法上从RStudio删除无法识别(未解码)的字符。使用iconv函数无法正常工作。如何解决下图所示的问题?

enter image description here

RStudio在我的编辑器中无法识别的文本:

  

这是无法在RStudio pp.10-11)Pub中解码的文本

上面的代码:

text <- readClipboard()
rstudioapi::insertText(text) # Insert the text to the editor
# This is how it looks like
"This is a text that cannot be decoded in RStudio: pp. 10–11: "

# If I change the encoding:
text <- iconv(text, "UTF-8", "UTF-8", sub='')
# Output that I get is without "–" as well:
rstudioapi::insertText(text)
"This is a text that cannot be decoded in RStudio: pp.1011: " # Output without "-"

# This is what I want is just to remove dot with pink character:
rstudioapi::insertText(text)
"This is a text that cannot be decoded in RStudio: pp.10–11: "

0 个答案:

没有答案