2

だから、私がやっていることは、ブラウズボタンをクリックすると、ユーザーがファイルを保存したり、ファイルを探したりするディレクトリに直接移動できるようにすることです。

例えば

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

ただし、以前のスクリプトでは、作業ディレクトリを既に設定しています

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

そのため、最初の例を実行すると、ディレクトリ Program ではなくgraph に移動しました。しかし、2回目にfile.choose()を実行すると、グラフディレクトリに移動したのはなぜですか? これを修正する方法はありますか?

4

1 に答える 1

2

あなたの問題に対する迅速で汚い解決策は次のとおりです。

 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()
于 2013-10-26T13:14:28.980 に答える