Error while reading csv file

耗尽温柔 提交于 2019-12-13 09:27:19

问题


I have a xlsx file and to read from Rstudio i saved it as .csv file. Now when i try to read the file from Rstudio, receiving the below error.

setwd("D:/DATA SCIENCE/CCPP-Linear regression")
ccpp<- read.csv("Folds5x2_pp.csv", header = TRUE)

Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") : cannot open file 'Folds5x2_pp.csv': No such file or directory


回答1:


As already mentioned in the comments, the "cannot open the connection" part of the error message confirms that where R is looking is not where the file is.

A few things to keep in mind

  • use getwd() to see the current R working directory
  • use setwd() to change R's wd
  • You should use RStudio projects to organize your projects - this helps with the working directory thing
  • spaces in paths are difficult sometimes. Looks like you have "D:/DATA SCIENCE", that space can cause problems (you may need to escape the space like "DATA\ SCIENCE".
  • You can read the file using the full path (e.g. read.csv("D:/DATA SCIENCE/path/file.csv")) or if you are doing this a lot, set a variable to your path data_path ="D:/DATA SCIENCE/path/" and then read.csv(file.path(data_path, "file.csv")) where file.path concatenates with your OS specific path delimiter.
  • You can import files into RStudio using the Import Dataset option under Tools in the menu bar.


来源:https://stackoverflow.com/questions/39708725/error-while-reading-csv-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!