[R] Cannot read in a csv file.

John Kane jrkrideau at yahoo.ca
Sun May 8 01:14:15 CEST 2011



--- On Sat, 5/7/11, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

> From: Duncan Murdoch <murdoch.duncan at gmail.com>
> Subject: Re: [R] Cannot read in a csv file.
> To: "John Kane" <jrkrideau at yahoo.ca>
> Cc: r-help at r-project.org
> Received: Saturday, May 7, 2011, 4:20 PM
> On 11-05-07 1:26 PM, John Kane
> wrote:
> > Can anyone suggest why this file  http://www.mediafire.com/?afeyhhpacaq
> > is refusing to open for me.?
> >
> > I must admit I don't know all its history but the
> original data was taken from an OOo spreadsheet that I
> edited (good bit of copying and pasting and the month
> variable added by hand in OOo Calc) and, then,saved as a csv
> file.  It was not originally an English language file
> as far as I can determine.  It may have been created in
> Excel for all I know.
> >
> > If I load the file into my text editor (Tinn-r) I can
> read the material in using the textConnection command and
> have no problem working with it.  However this meant
> that I spend an hour and a half trying to read the file and
> 5 minutes doing the graph I wanted.  I'd like to avoid
> my mistake in the future if possible.
> >
> > I'm showing my last try below but the directory is
> almost certainly correct. I've tried it  using a full
> path name and, as below, after changing the active
> directory.
> >
> > When I try to load the file  I get this:
> >
> >> read.csv("asp.csv", header=TRUE, sep=",")
> >
> > Error in file(file, "rt") : cannot open the
> connection
> > In addition: Warning message:
> > In file(file, "rt") : cannot open file 'asp.csv': No
> such file or directory
> >
> 
> If the filename is really correct, then it would appear to
> be a 
> permissions problem.  Do you have read permission on
> that file?  Try 
> opening it in Notepad or some other program.
No problem with permissions


> 
> If that works, then I'd suggest that you actually don't
> have the 
> filename correct.  (Windows does dumb things like
> displaying the file 
> "asp.csv.txt" as "asp.csv" by default.)  If you use
> the file.choose() 
> function to select the file, you'll get the right
> filename.
That's it.  Somehow I managed to introduce an extra . in the file name and somehow never noticed it.

file.choose() gave 
"C:\\rdata\\asp..csv" 

Must be the new glasses. If I take them off and peer at the screen from about 3 inches I can see the extra dot!

Thanks very much.
> Duncan Murdoch
> 
> > sessionInfo()
> >
> > R version 2.12.2 (2011-02-25)
> > Platform: i386-pc-mingw32/i386 (32-bit)
> >
> > locale:
> > [1] LC_COLLATE=English_Canada.1252 
> LC_CTYPE=English_Canada.1252
> > [3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
> > [5] LC_TIME=English_Canada.1252
> >
> > attached base packages:
> > [1] grid      stats 
>    graphics  grDevices utils 
>    datasets 
> methods   base
> >
> > other attached packages:
> > [1] ggplot2_0.8.9 proto_0.3-9.1 reshape_0.8.4
> plyr_1.4.1
> >
> > loaded via a namespace (and not attached):
> > [1] digest_0.4.2 tools_2.12.2
> >>
> >
> > Thanks.
> >
> > ______________________________________________
> > R-help at r-project.org
> mailing list
> > 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.
> 
>


More information about the R-help mailing list