Issues with loading csv file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Issues with loading csv file

Shivi82
HI All,

I am trying to load an CSV file into the R project. the code for the same is:
mydata<- read.csv("Jan-May Data.csv", header=TRUE)

however with this I am getting the below error message:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'Jan-May Data.csv': No such file or directory


I am under the impression that R automatically pulls the data from the working directory and we do not have to add the location where the file is saved. Please let me know if my understanding is correct and help on the error as well.

Please note the csv file is already saved in the WD.
Thank you, Shivi
Reply | Threaded
Open this post in threaded view
|

Re: Issues with loading csv file

Kevin Thorpe
On 05/25/2015 08:19 AM, Shivi82 wrote:

> HI All,
>
> I am trying to load an CSV file into the R project. the code for the same
> is:
> mydata<- read.csv("Jan-May Data.csv", header=TRUE)
>
> however with this I am getting the below error message:
> /*Error in file(file, "rt") : cannot open the connection
> In addition: Warning message:
> In file(file, "rt") :
>    cannot open file 'Jan-May Data.csv': No such file or directory*/
>
> I am under the impression that R automatically pulls the data from the
> working directory and we do not have to add the location where the file is
> saved. Please let me know if my understanding is correct and help on the
> error as well.
>
> Please note the csv file is already saved in the WD.
> Thank you, Shivi
>

The error message suggests that R is not finding the file. Are you sure
it is in R's working directory? Try explicitly setting the working
directory to the directory (folder) where your CSV file is. There is a
menu option for this.

Kevin

--
Kevin E. Thorpe
Head of Biostatistics,  Applied Health Research Centre (AHRC)
Li Ka Shing Knowledge Institute of St. Michael's
Assistant Professor, Dalla Lana School of Public Health
University of Toronto
email: [hidden email]  Tel: 416.864.5776  Fax: 416.864.3016

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Issues with loading csv file

J Robertson-Burns
In reply to this post by Shivi82
I suggest two commands to diagnose
the problem:

getwd()  # show the working directory of R

This is navigation tool #17.
http://www.burns-stat.com/r-navigation-tools/

list.files()  # show the files in the working directory

You can copy and paste file names to avoid
typing mistakes.  (Not that I've ever made any.)

Pat

On 25/05/2015 13:19, Shivi82 wrote:

> HI All,
>
> I am trying to load an CSV file into the R project. the code for the same
> is:
> mydata<- read.csv("Jan-May Data.csv", header=TRUE)
>
> however with this I am getting the below error message:
> /*Error in file(file, "rt") : cannot open the connection
> In addition: Warning message:
> In file(file, "rt") :
>    cannot open file 'Jan-May Data.csv': No such file or directory*/
>
> I am under the impression that R automatically pulls the data from the
> working directory and we do not have to add the location where the file is
> saved. Please let me know if my understanding is correct and help on the
> error as well.
>
> Please note the csv file is already saved in the WD.
> Thank you, Shivi
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Issues-with-loading-csv-file-tp4707637.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Issues with loading csv file

Michael Dewey-3
In reply to this post by Shivi82
You could try list.files() which will tell you which files R thinks are
in your working directory.

On 25/05/2015 13:19, Shivi82 wrote:

> HI All,
>
> I am trying to load an CSV file into the R project. the code for the same
> is:
> mydata<- read.csv("Jan-May Data.csv", header=TRUE)
>
> however with this I am getting the below error message:
> /*Error in file(file, "rt") : cannot open the connection
> In addition: Warning message:
> In file(file, "rt") :
>    cannot open file 'Jan-May Data.csv': No such file or directory*/
>
> I am under the impression that R automatically pulls the data from the
> working directory and we do not have to add the location where the file is
> saved. Please let me know if my understanding is correct and help on the
> error as well.
>
> Please note the csv file is already saved in the WD.
> Thank you, Shivi
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Issues-with-loading-csv-file-tp4707637.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
Michael
http://www.dewey.myzen.co.uk/home.html

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Issues with loading csv file

WRAY NICHOLAS
In reply to this post by Shivi82
Something you could try is to put a small csv file into a location and set
the word to that and see whether it's finding it
eg
setwd("C:/Users/Shivi/Documents/")
open this file, stick a csv doc and see whether R will read it

Nick

On 25 May 2015 at 13:19, Shivi82 <[hidden email]> wrote:

> HI All,
>
> I am trying to load an CSV file into the R project. the code for the same
> is:
> mydata<- read.csv("Jan-May Data.csv", header=TRUE)
>
> however with this I am getting the below error message:
> /*Error in file(file, "rt") : cannot open the connection
> In addition: Warning message:
> In file(file, "rt") :
>   cannot open file 'Jan-May Data.csv': No such file or directory*/
>
> I am under the impression that R automatically pulls the data from the
> working directory and we do not have to add the location where the file is
> saved. Please let me know if my understanding is correct and help on the
> error as well.
>
> Please note the csv file is already saved in the WD.
> Thank you, Shivi
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Issues-with-loading-csv-file-tp4707637.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Issues with loading csv file

Shivi82
In reply to this post by J Robertson-Burns
Hi Pat,

Thanks for the suggestion. It worked for me.
Actually I had not saved the file in the WD accidentally and with the help of get files syntax I got to know what was the issue.

Thanks a ton.
Shivi