On 3/26/2009 9:09 AM, Shay O'Farrell wrote:
Hi all,

I’m new to R, and I’m having a small but annoying problem with the choose.files command, using version 2.8.1 in Windows XP. I am holding my data text files in C:\\Data\\, and I’m writing a short script that first resets the default directory to this directory, then allows me to interactively select which text file to import and attach, using the Windows widget. Here is my script:

setwd("C:\\Data\\")
data<-read.table(choose.files(),header=T,as.is=T)
attach(data)

If I copy and paste the script into R Editor (or directly into RGui) and run it, it works perfectly. However, if have imported the script using the Open Script button in RGui, then I have a glitch... when I run the script, the widget looks in the last folder that I opened interactively (i.e., the folder from which I imported my script file) instead of looking in the new working directory. BUT... if I run line 3 again straight after, it works perfectly the second time. What am I doing wrong? Any help would be appreciated.

If you don't specify where to open the dialog, it will open in the last location where it was opened. This saves time if you are running it more than once, because often you will open files from the same directory. If you don't want that, you can specify which directory to open, and get it to always open in the current directory using choose.files("./*").

Duncan Murdoch

______________________________________________
R-help@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.

Reply via email to