簡體   English   中英

R Windows 操作系統選擇.dir() 文件選擇器不會在工作目錄中打開

[英]R Windows OS choose.dir() File chooser won't open at working directory

choose.dir 函數參考頁面有一個例子:

choose.dir(getwd(), "Choose a suitable folder")

這應該在工作目錄中啟動文件夾選擇窗口。 但是,我只在“我的電腦”中打開了文件夾選擇窗口。 此功能無法按預期工作的原因是什么?

你是對的,你不應該使用choose.dir() ,因為它是特定於操作系統的。 我確實可以重現您報告的問題 - 我的猜測是它不會讓您在屬於“Root”用戶的目錄中啟動(無論在 Windows 中可能意味着什么),因為它似乎適用於其他目錄,不在“根”下:

 getwd()
 # [1] "C:/Users/Root/Documents"
 choose.dir(getwd(), "Choose a suitable folder") # leads to 'Computer'

 setwd("C:/datathon")
 choose.dir(getwd(), "Choose a suitable folder") # select subfolder 'scripts', works OK
 # [1] "C:\\datathon\\scripts"

有兩種獨立於操作系統的解決方案; 第一個,正如之前所 指出的,是使用tcltk包中的以下功能:

 library(tcltk)
 setwd('~')
 getwd()
 # [1] "C:/Users/Root/Documents"
 dir <- tclvalue(tkchooseDirectory())  # opens a dialog window in 'My Documents'

第二種是使用rChoiceDialogs包(需要rJava ):

 library(rJava)
 library(rChoiceDialogs)
 getwd()
 # [1] "C:/Users/Root/Documents"
 jchoose.dir()  # opens the dialog window in "C:\\Users\\Root\\Documents"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM