Shay O'Farrell
2009-Mar-26 13:09 UTC
[R] problem with "choose.files" command & interactive functions
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. Thanks Shay
Duncan Murdoch
2009-Mar-26 13:20 UTC
[R] problem with "choose.files" command & interactive functions
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
Apparently Analagous Threads
- interactive 2-D plot interrogation
- How to GSSAPI/Kerberos authenticate with Dovecot [formerly Where is krb5.keytab or equivalent?]
- How to GSSAPI/Kerberos authenticate with Dovecot [formerly Where is krb5.keytab or equivalent?]
- getent problems with new Samba version
- use of the tcltk package crashes R 4.0.1 for Windows