Dear R-users, I am a new user for R. I am eager to lean about it. I wanted to read and summary of the a simple data file I used the following, rel <- read.table("C:/Documents and Settings/ashta/My Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names c("id","orel","nrel")) summary(rel) Below is the error message, rel <- read.table("C:/Documents and Settings/ashta/My Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names + c("id","orel","nrel")) Error in file(file, "r") : cannot open the connection In addition: Warning message: In file(file, "r") : cannot open file 'file=C:/Documents and Settings/sewalem/My Documents/R_data/rel.dat': Invalid argument> summary(rel)Error in summary(rel) : object 'rel' not found Does it need a library? Where can I get the library? Any help is highly appreciated Ashta [[alternative HTML version deleted]]
Hello Ashta, You need to use double blackslashes, liike: "C:\\Documents and Settings\\ashta\\MyDocuments\\R_data\\rel.dat" I usually use the following to avoid writing the path: #select file from a popup window f <- file.choose() #read the file. the .... is Rese for any other arguments e.g. header, sep. quote, etc. data <- read.table(f, ...) Good luck! and welcome to R. Keo. Ashta escribi?:> Dear R-users, > > I am a new user for R. I am eager to lean about it. > > > > I wanted to read and summary of the a simple data file > > > > I used the following, > > > > > > rel <- read.table("C:/Documents and Settings/ashta/My > Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names> > c("id","orel","nrel")) > > summary(rel) > > > > > > Below is the error message, > > > > rel <- read.table("C:/Documents and Settings/ashta/My > Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names> > + c("id","orel","nrel")) > > Error in file(file, "r") : cannot open the connection > > In addition: Warning message: > > In file(file, "r") : > > cannot open file 'file=C:/Documents and Settings/sewalem/My > Documents/R_data/rel.dat': Invalid argument > > >> summary(rel) >> > > Error in summary(rel) : object 'rel' not found > > > > Does it need a library? Where can I get the library? > > > > Any help is highly appreciated > > > > Ashta > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
What it is telling you is that it can't find the file. This could be because the file isn't there, or you've got a typo in the file name, that sort of thing. In your email, you have split the filename argument between two lines. I don't know whether this comes from what you did in R, or whether it was put there by the email software. If the former, try it without the line break, like this: rel <- read.table("C:/Documents and Settings/ashta/My Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names c("id","orel","nrel")) NOT rel <- read.table("C:/Documents and Settings/ashta/My Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names c("id","orel","nrel")) This is a bit of a wild guess, since I don't use R in Windows, and I don't know how the R GUI for Windows handles a line break in the filename in context of read.table(). But it could be the problem. Also, isn't there supposed to be a space between "My" and "Documents"? As best I can tell from your email, you don't have one -- but it's hard to tell because it's split into two lines. -Don At 8:42 AM -0400 9/23/09, Ashta wrote:>Dear R-users, > > I am a new user for R. I am eager to lean about it. > > > >I wanted to read and summary of the a simple data file > > > >I used the following, > > > > > >rel <- read.table("C:/Documents and Settings/ashta/My >Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names> >c("id","orel","nrel")) > >summary(rel) > > > > > >Below is the error message, > > > >rel <- read.table("C:/Documents and Settings/ashta/My >Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names> >+ c("id","orel","nrel")) > >Error in file(file, "r") : cannot open the connection > >In addition: Warning message: > >In file(file, "r") : > > cannot open file 'file=C:/Documents and Settings/sewalem/My >Documents/R_data/rel.dat': Invalid argument > >> summary(rel) > >Error in summary(rel) : object 'rel' not found > > > >Does it need a library? Where can I get the library? > > > >Any help is highly appreciated > > > >Ashta > > [[alternative HTML version deleted]] > >______________________________________________ >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.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062
On 09/23/2009 10:42 PM, Ashta wrote:> Dear R-users, > > I am a new user for R. I am eager to lean about it. > > > > I wanted to read and summary of the a simple data file > > > > I used the following, > > > > > > rel<- read.table("C:/Documents and Settings/ashta/My > Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names> > c("id","orel","nrel")) > > summary(rel) > > > > > > Below is the error message, > > > > rel<- read.table("C:/Documents and Settings/ashta/My > Documents/R_data/rel.dat", quote="",header=FALSE,sep="",col.names> > + c("id","orel","nrel")) > > Error in file(file, "r") : cannot open the connection > > In addition: Warning message: > > In file(file, "r") : > > cannot open file 'file=C:/Documents and Settings/sewalem/My > Documents/R_data/rel.dat': Invalid argument > > >> summary(rel) >> > Error in summary(rel) : object 'rel' not found > > > > Does it need a library? Where can I get the library? > > >Hi Ashta, If you have checked that the file "rel.dat" is really there where you think it is, there is a nasty trick that Windows plays with many files. For example, if you have created this file in Notepad and saved it, you may find that .txt has been added to the filename. So the real filename is "rel.dat.txt". Of course, Windows won't show you that unless you go into Folder Options in Windows Explorer and turn off that "Hide known extensions" option. This is a wild guess, but it has happened to me so often that I am wary of it. Jim