hello there, I'm a new user to R and I am having difficulty reading a file into the program. Here's the error I keep getting, I bet there's a simple solution, but I cant find any... Error in file(file, "r") : unable to open connection In addition: Warning message: cannot open file `c:MikeWeather2.txt' I have made sure that my working directory is the same as the place where the file is. I have also tried using the full path name of the file. read.table, read.delim, read.csv, and scan have all been attempted with no result. What causes this message, and how can I fix it. Thanks in advance for your help, Mike
If your working directory contains a file you want to read then the following should work: dat <- read.table("filename.txt") If you want to use absolute paths, you have to be careful with the '\' because that is an escape character... so try: dat <- read.table("c:/some/path/notice/forward/slashes/data.txt") # or dat <- read.table("c:\\double\\back\\should\\work\\data.txt") On Thu, Jan 29, 2004 at 09:19:23AM -0700, mpalmier at mines.edu wrote:> hello there, > I'm a new user to R and I am having difficulty reading a file into the > program. Here's the error I keep getting, I bet there's a simple solution, > but I cant find any... > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file `c:MikeWeather2.txt' > > I have made sure that my working directory is the same as the place where the > file is. I have also tried using the full path name of the file. read.table, > read.delim, read.csv, and scan have all been attempted with no result. What > causes this message, and how can I fix it. Thanks in advance for your help, > > Mike > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> I'm a new user to R and I am having difficulty reading a file into the > program. Here's the error I keep getting, I bet there's a simple solution, > but I cant find any... > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file `c:MikeWeather2.txt'I am guessing that you didn't escape the backslash in the filename 'c:\MikeWeather2.txt', so you would have to refer to it as 'c:\\MikeWeather2.txt' in R. But, since you didn't show what you did to spawn the error, I could be wrong
See the rw-FAQ Q2.14 R can't find my file, but I know it is there! I'd be interested to know why you didn't find that -- the posting guide does ask you to read the rw-FAQ, so I presume there is connection that is not obvious to you. On Thu, 29 Jan 2004 mpalmier at mines.edu wrote:> hello there, > I'm a new user to R and I am having difficulty reading a file into the > program. Here's the error I keep getting, I bet there's a simple solution, > but I cant find any... > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file `c:MikeWeather2.txt'I guess a \ is missing there, as addressed in Q2.14.> I have made sure that my working directory is the same as the place > where the file is.In that case you don't need c:, do you?> I have also tried using the full path name of the file. read.table, > read.delim, read.csv, and scan have all been attempted with no result. > What causes this message, and how can I fix it. Thanks in advance for > your help,-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Thu, 29 Jan 2004 09:19:23 -0700, mpalmier at mines.edu wrote :>hello there, > I'm a new user to R and I am having difficulty reading a file into the >program. Here's the error I keep getting, I bet there's a simple solution, >but I cant find any... > >Error in file(file, "r") : unable to open connection >In addition: Warning message: >cannot open file `c:MikeWeather2.txt' > >I have made sure that my working directory is the same as the place where the >file is. I have also tried using the full path name of the file. read.table, >read.delim, read.csv, and scan have all been attempted with no result. What >causes this message, and how can I fix it. Thanks in advance for your help, > >Mike > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlYou don't give enough detail to diagnose the problem. What command did you use? How did you make sure your working directory was right? What version of R and what operating system are you using? Please read the posting guide mentioned at the bottom of your message. Duncan Murdoch
> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > mpalmier at mines.edu > Sent: Friday, January 30, 2004 5:19 AM > To: R-help at lists.R-project.org > Subject: [R] please help me! > > > hello there, > I'm a new user to R and I am having difficulty reading a > file into the > program. Here's the error I keep getting, I bet there's a > simple solution, > but I cant find any... > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file `c:MikeWeather2.txt' >How did you get this error message? It would help if you put your codes here. But I'm guessing it is because you typed something like: foo = read.table("C:\MikeWeather2.txt") Try to use "C:/MikeWeather2.txt" or "C:\\MikeWeather2.txt". HTH. Kevin -------------------------------------------- Ko-Kang Kevin Wang, MSc(Hon) Statistics Workshops Co-ordinator Student Learning Centre University of Auckland New Zealand
If I may make a suggestion, it helps if you use informative subject lines in your email to a high-traffic list like this. mpalmier at mines.edu writes:> hello there, > I'm a new user to R and I am having difficulty reading a file into the > program. Here's the error I keep getting, I bet there's a simple solution, > but I cant find any... > > Error in file(file, "r") : unable to open connection > In addition: Warning message: > cannot open file `c:MikeWeather2.txt' > > I have made sure that my working directory is the same as the place where the > file is. I have also tried using the full path name of the file. read.table, > read.delim, read.csv, and scan have all been attempted with no result. What > causes this message, and how can I fix it. Thanks in advance for your help,I always find it tedious to remember how to write file names in Windows (there are rules about '\' and '/' characters) so I use the file.choose() function, which brings up a chooser panel. Although you haven't said what you want to do with the file, let's assume you are going to source some R code in the file. Then you could use source(file.choose())