R脚本文件编码(R Studio)
我必须使用哪种文件编码才能在R脚本中正确保存此向量()?这些特殊的汉字和中国符号似乎让事情变得复杂起来R脚本文件编码(R Studio),r,encoding,R,Encoding,我必须使用哪种文件编码才能在R脚本中正确保存此向量()?这些特殊的汉字和中国符号似乎让事情变得复杂起来 x <- c("http://foo.com/blah_blah", "http://foo.com/blah_blah/", "(Something like http://foo.com/blah_blah)", "http://foo.com/blah_blah_(wikipedia)", "http://foo
x <- c("http://foo.com/blah_blah",
"http://foo.com/blah_blah/",
"(Something like http://foo.com/blah_blah)",
"http://foo.com/blah_blah_(wikipedia)",
"http://foo.com/more_(than)_one_(parens)",
"(Something like http://foo.com/blah_blah_(wikipedia))",
"http://foo.com/blah_(wikipedia)#cite-1",
"http://foo.com/blah_(wikipedia)_blah#cite-1",
"http://foo.com/unicode_(✪)_in_parens",
"http://foo.com/(something)?after=parens",
"http://foo.com/blah_blah.",
"http://foo.com/blah_blah/.",
"<http://foo.com/blah_blah>",
"<http://foo.com/blah_blah/>",
"http://foo.com/blah_blah,",
"http://www.extinguishedscholar.com/wpglob/?p=364.",
"http://✪df.ws/1234",
"rdar://1234",
"rdar:/1234",
"x-yojimbo-item://6303E4C1-6A6E-45A6-AB9D-3A908F59AE0E",
"message://%3c330e7f840905021726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e",
"http://➡.ws/䨹",
"www.c.ws/䨹",
"<tag>http://example.com</tag>",
"Just a www.example.com link.",
"http://example.com/something?with,commas,in,url, but not at end",
"What about <mailto:gruber@daringfireball.net?subject=TEST> (including brokets).",
"mailto:name@example.com",
"bit.ly/foo",
"“is.gd/foo/”",
"WWW.EXAMPLE.COM",
"http://www.asianewsphoto.com/(S(neugxif4twuizg551ywh3f55))/Web_ENG/View_DetailPhoto.aspx?PicId=752",
"http://www.asianewsphoto.com/(S(neugxif4twuizg551ywh3f55))",
"http://lcweb2.loc.gov/cgi-bin/query/h?pp/horyd:@field(NUMBER+@band(thc+5a46634))")
x运行您的示例
source('file.R', encoding="unknown")
工作正常,另存为R对象,重新加载也可以:
save(x, file='kk.Rd')
load('kk.Rd')
您可以使用iconvlist()
获取所有不同的编码并对其进行测试,例如:
vals <- lapply(iconvlist(), function(x)
tryCatch(source('file.R', encoding=x),
error=function(e)return(NULL)))
提供加载时未引发错误的所有编码
这有帮助吗?运行您的示例
source('file.R', encoding="unknown")
工作正常,另存为R对象,重新加载也可以:
save(x, file='kk.Rd')
load('kk.Rd')
您可以使用iconvlist()
获取所有不同的编码并对其进行测试,例如:
vals <- lapply(iconvlist(), function(x)
tryCatch(source('file.R', encoding=x),
error=function(e)return(NULL)))
提供加载时未引发错误的所有编码
这有帮助吗?您目前使用哪种编码?getOption(“编码”)
为您提供了什么?我尝试了source('file.R',encoding=“native.enc”)
和source('file.R',encoding=“unknown”)
,您的脚本是file.R
,向量可以读取。我不确定我现在看到的“特殊字符和中文”是否与您看到的相同,因为它取决于我们浏览器的编码(主要是UTF-8)。我想也许检查浏览器的编码并将IDE更改为相同的编码就可以了。您现在使用哪种编码?getOption(“编码”)
为您提供了什么?我尝试了source('file.R',encoding=“native.enc”)
和source('file.R',encoding=“unknown”)
,您的脚本是file.R
,向量可以读取。我不确定我现在看到的“特殊字符和中文”是否与您看到的相同,因为它取决于我们浏览器的编码(主要是UTF-8)。我想也许可以检查浏览器的编码并将IDE更改为相同的编码。我手动尝试了各种编码,每次打开R脚本时,所提到的符号都显示错误(即被其他符号替代)。这意味着,没有错误,但内容仍然是错误的。当我在Rstudio中打开文件时,看起来所有符号都显示正确。哪些符号会失败?您在哪个平台上工作?我手动尝试了各种编码,每次打开R脚本时,所提到的符号都显示错误(即被其他符号替代)。这意味着,没有错误,但内容仍然是错误的。当我在Rstudio中打开文件时,看起来所有符号都显示正确。哪些符号会失败?你在哪个站台工作?