R安装星人,因为某些原因要从Python转而"预习"用R…结果在读取数据上遇到了七昏古去的bug*2。分别对应两种读取excel的方式。
BUG1 about xlsx
#参考[R菜鸟教程](https://www.runoob.com/r/r-input-excel-file.html)使用 xlxs包
library(xlsx)
data1 = read.xlsx("d_tip_record.xlsx",1)
#但是报错如下:
Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :
java.lang.OutOfMemoryError: Java heap space
解决方案使用readxl
来源:https://community.rstudio.com/t/java-lang-outofmemoryerror-in-r/115219
It’s impossible to say since only you have access to this file. However, as one suggestion, you can try reading your Excel file using a different package - readxl(more info on how to install and use it here - https://github.com/tidyverse/readxl).
也就是说,一般来说使用xlsx是没问题的,但是我这台电脑这个环境此时此刻不行;所以我尝试使用readxl。
readxl_22">BUG2 about readxl
#参照readxl的教程
library(readxl)#记得install哈 install.packages("readxl")
example<-read_excel("d_choose_record.xlsx")
example<-read_excel("/users/d_choose_record.xlsx")
错误:
filepath: d_choose_record.xlsx
libxls error: Unable to open file
readxl_33">solution: readxl
#修改R的工作环境,似乎参数只能是相对路径。
getwd()#显示路径
setwd("/Users/.../code")
#记得改成自己的路径,而后执行:
example<-read_excel("d_choose_record.xlsx")
#读取成功,分析数据的第一步done!
参考来源
1.R语言菜鸟教程
2.readxl的官网
3.R语言Excel的读写