刚学习R语言,老师给的.Rdata格式的文件(我也不知道源文件是本文件还是excl文件啥的),我就打不开了~~~~(>_<)~~~~ ,载入foreign包也不行,大神帮忙看看这到底问题出在哪里了啊?该怎么解决呢?万分感谢!!
情况一:
> dfrm<-read.table("G:/课件及作业/R语言建模/Rdata for homework/example2_5.RData")
Error in make.names(col.names, unique = TRUE) :
invalid multibyte string 1
In addition: Warning messages:
1: In read.table("G:/课件及作业/R语言建模/Rdata for homework/example2_5.RData") :
line 1 appears to contain embedded nulls
2: In read.table("G:/课件及作业/R语言建模/Rdata for homework/example2_5.RData") :
line 4 appears to contain embedded nulls
3: In read.table("G:/课件及作业/R语言建模/Rdata for homework/example2_5.RData") :
incomplete final line found by readTableHeader on 'G:/璇句欢鍙婁綔涓?R璇瑷寤烘ā/Rdata for homework/example2_5.RData'
情况二:添加head=TRUE以后
>dfrm<-read.table("G:/课件及作业/R语言建模/Rdata for homework/example2_5.RData",head=TRUE)
Error in make.names(col.names, unique = TRUE) :
invalid multibyte string 1
In addition: Warning messages:
1: In grepl("\n", lines, fixed = TRUE) :
input string 1 is invalid in this locale
2: In grepl("\n", lines, fixed = TRUE) :
input string 1 is invalid in this locale
3: In grepl("\n", lines, fixed = TRUE) :
input string 1 is invalid in this locale
4: In read.table("G:/课件及作业/R语言建模/Rdata for homework/example2_5.RData", :
line 1 appears to contain embedded nulls
5: In read.table("G:/课件及作业/R语言建模/Rdata for homework/example2_5.RData", :
line 4 appears to contain embedded nulls
6: In read.table("G:/课件及作业/R语言建模/Rdata for homework/example2_5.RData", :
incomplete final line found by readTableHeader on 'G:/璇句欢鍙婁綔涓?R璇瑷寤烘ā/Rdata for homework/example2_5.RData'
I found some source and other IO functions which read the source code from file. On my courses, these scripts are stored with encoding UTF-8, but the default chinese encoding for Chinese Traditional windows users are BIG5. Similar issues might be occurred for other non-English courses.
The solution is to add the argument encoding = "UTF-8", in my case, to these functions or connections. More generally, providing the default encoding or a hook before parsing might be a more robust solution.