2

So what im doing is making my browse button so that when i click on them bring the user straight to the directory that i want them to save their file in or look for their file.

For example

     setwd("C:\\Users\\Eric\\Desktop\\Program\\graphs") #set directory
     file.choose()

However in the earlier script i have already set my work directory at

    setwd("C:\\Users\\Eric\\Desktop\\Proram") #set directory

so when i ran the first example it brought me to directory Program instead of graphs . but when i ran file.choose() on the second time, it then brought me to the graphs directory why is this happening? any idea how to fix this ?

Napmi
  • 521
  • 2
  • 13
  • 32

1 Answers1

2

Here's a quick and dirty solution to your problem:

 dirPath <- "C:\\Users\\Eric\\Desktop\\Program\\graphs"
 setwd(dirPath)
 # Tell R to sleep until the current directory matches the expected directory
 while(getwd() != normalizePath(dirPath)) {
   Sys.sleep(0.02)
 }
 file.choose()
Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64
  • Thanks , this totally worked! However , i realized if i were to transfer this script into another pc.... the setwd wont work cause the directory Eric will be different :/ . Thanks tho love this dirty solution of yours ! – Napmi Oct 26 '13 at 18:33