有特殊字符的斯堪的纳维亚读大的txt文件

问题描述:

我读包含瑞典字母A A o使用(readr)和(LAF)1 GB的txt文件打包有特殊字符的斯堪的纳维亚读大的txt文件

my.data<- read_fwf('my.file', fwf_widths (c(2,2,2,8,2,4,40,1,1,10,10,4,2,11,32,1,4)), 
progress = interactive()) 

喜欢,而不是o一个获取值的问题å

有什么建议吗?

斯堪的纳维亚性状有时需要特殊的编码,即#ISO-8859-1 - 拉丁1以下是关于编码(其不同于为每个计算/ OS)

#Check what is your present encoding: 
getOption("encoding") 
#Modifiy the encoding 
options(encoding = "ISO-8859-1") 

#Optional: Check your system locale (Time, Monetary System, etc) 
Sys.getlocale() 
#Set an encoding, but it is OS-dependent what is installed 
Sys.setlocale("LC_ALL", locale ="swe") 

从readr文档有用的命令:“默认编码,只影响文件的读取方式 - 读取器总是将输出转换为UTF-8。“随着read_fwf似乎你,可以指定一个区域设置/编码:

read_fwf(file, col_positions, col_types = NULL, locale = default_locale(), 
na = c("", "NA"), comment = "", skip = 0, n_max = Inf, 
guess_max = min(n_max, 1000), progress = show_progress()) 

更换default_locale()locale(encoding= "latin1")。你的例子是不可复制的,因此很难测试它是否有效,但它应该看起来像:

my.data<- read_fwf('my.file', fwf_widths (c(2,2,2,8,2,4,40,1,1,10,10,4,2,11,32,1,4)), locale= locale(encoding= "latin1"), 
progress = interactive())