Skip to content

please help me!

8 messages · mpalmier@mines.edu, Seth Falcon, Jeff Gentry +4 more

#
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:
#
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:

            
I guess a \ is missing there, as addressed in Q2.14.
In that case you don't need c:, do you?

  
    
#
On Thu, 29 Jan 2004 09:19:23 -0700, mpalmier at mines.edu wrote :
You 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
#
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:
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())
#
On 29 Jan 2004 14:20:26 -0600, you wrote:

            
I've occasionally thought that "file = file.choose()" would be better
than no default in a lot of functions that take filenames as
arguments, e.g. file, the read* and write* functions, the bitmap
device, Sweave, etc.

Duncan Murdoch