我試圖在R中複製shell命令,但無法弄清楚如何將命令串在一起。這只是返回的工作文件夾中的內容(system()
由於某種原因失敗):Windows中的多個shell命令
> shell("dir")
Volume info ..
Directory of E:\Documents\R
contents are listed..
現在讓我們嘗試並導航到C盤並運行dir
(不使用明顯dir C:
)..
> shell("cd C:")
C:\
> shell("dir")
Volume in drive E is GT
etc..
所以看起來命令不能單獨輸入,因爲shell不記得工作目錄。所以..
> (cmd = "cd C:
+ dir")
[1] "cd C:\ndir"
> shell(cmd)
C:\
沒有運氣,因爲C:文件夾沒有報告。我試過的其他方法也失敗了。感謝任何想法。
作爲康拉德指出,有更好的方法來獲得'R'完成任務。例如,使用具有指定路徑名的'R'的'dir'函數。 'dir(path ='E:/ documents/r',pattern ='whatever ...')' –