简体   繁体   中英

Error while reading csv file

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

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM