Encoding in R: How to convert this string to UTF-8

2019-08-06 11:50发布

I am using R to read data from an old fame database. This works fine in general but I get unexpected encoding back when reading descriptions. E.g.:

a <- "\U3e34653c"
# is supposed to be 
"ä"

I tried to iconv my self around this problem but despite trying numerous possibilities I was not able to get it displayed in a proper way. my locale: en_US.UTF-8. Is there a way around replacing (sub) such strings?

标签: r encoding utf-8
2条回答
一纸荒年 Trace。
2楼-- · 2019-08-06 12:06

I had an identical problem when extracting data from SQL Server (via ODBC and the RODBC package). I solved it by changing the settings on the ODBC driver to treat all strings as unicode.

More specifically, I'm using Actual Technologies ODBC driver for SQL Server and under 'Advanced Language Settings' can specify 'Treat text types as Unicode' with an option for 'Multi-byte text encoding' to be set to UTF-8.

查看更多
仙女界的扛把子
3楼-- · 2019-08-06 12:13

Try opening the files with a different encoding string? As Ricardo suggests, perhaps Latin1? If not maybe some other exotic flavours:

f <- file( "myfile.db" , encoding = "Latin-1" )
dat <- readLines( f )

Can you link to some data?

查看更多
登录 后发表回答