Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open CSV file in R when R says "no such file or directory"?

Tags:

r

I have an excel file that I want to open in R. I tried both of these commands after saving the excel file as a csv file or a text file.

read.table() or read.csv()

I think part of the problem is where the file is located. I have it saved on the desk top. What am I missing here?

Here is the R output

In file(file, "rt") :   cannot open file 'Rtrial.csv': No such file or directory > help.search("read.csv") > read.csv("Rtrial.csv") Error in file(file, "rt") : cannot open the connection In addition: Warning message: In file(file, "rt") :   cannot open file 'Rtrial.csv': No such file or directory > read.table("tab") 
like image 558
illbill Avatar asked Apr 06 '11 15:04

illbill


People also ask

What do you do when R says no such file or directory?

you can use the command file. choose() and then follow the menu to find the file you want. This function will return the correct path to the file. Paths become much easier to deal with if you use projects in Rstudio (file -> new project), as then you can use relative paths from the project directory.

How do I open a CSV file in R?

To load a. csv file into the current script and operate with it, use the read. csv() method in base R. The output is delivered as a data frame, with row numbers given to integers starting at 1.

How do I find the location of a csv file in R?

You can use getwd() (to find the current path of the R process) or file. choose() to interactively find the file (it will return a character of the full path to the file). If you don't want to learn from this and/or do it with different files all the time, then you can short-circuit it with read. csv(file.


1 Answers

To throw out another option, why not set the working directory (preferably via a script) to the desktop using setwd('C:\John\Desktop') and then read the files just using file names

like image 73
Maiasaura Avatar answered Sep 22 '22 23:09

Maiasaura