On Tue, 19 Oct 2004, shizhu zang wrote:
> Hi, there.
> I am trying to read a file into R, but I got following message
> Error in file(file, "r") : unable to open connection In addition:
Warning message: cannot open file `SwirlSample.txt' .
> In fact, my file has been already in the current working directory.
> My R is running on window operation system instead of UNIX.
There are a couple of things that even experienced users of Windows can
find useful to note: one is the nice little function called list.files(),
which shows you the files in the current working directory. It happens
that R is not started in the directory you think, and this shows you what
is in your working directory; you can see the name of the working
directory with the getwd() function (R for Windows FAQ 2.12).
Secondly, you can change your working directory either from the File menu,
or with the setwd() function.
Thirdly, you can put file.choose() in place of the file name when you are
reading your file, which lets you choose the file interactively - this
also helps if you have difficulty understanding how R deals with
backslashes and forward slashes in file names with directory names (this
is R for Windows FAQ 2.14). I find it helps to think of directory name
separators like web page addresses, using forward slashes does work.
Finally, remember that Windows may hide the extension part of the file
name, so that the real name of the file may be different from what Windows
Explorer shows you (unsetting "Hide file extension for known file
types"
in the View tab of Folder alternatives under the Tools menu works, I'm not
sure if I've translated these right). If you have downloaded a file using
a web browser, you often find that it adds an extra extension (often
.txt), making it seem that the file isn't there, while it only has a
different name than the name Windows shows you. This can be abated by
always choosing "All files" before saving. (I think these are among
the
most frequently asked questions for people starting R under Windows).
> Thanks.
> Shizhu Zang
> Department of Biochemsitry
> Peking University
> Beijing
> China
>
>
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no