我對R有點新,並且對我正在編寫的程序有疑問。我希望能夠用一個while循環(最終使用每個read.table)接收文件(與用戶一樣多),但它一直在打斷我。 這是我到目前爲止有:R:雖然循環輸入
cat("Please enter the full path for your files, if you have no more files to add enter 'X': ")
fil<-readLines(con="stdin", 1)
cat(fil, "\n")
while (!input=='X' | !input=='x'){
inputfile=input
input<- readline("Please enter the full path for your files, if you have no more files to add enter 'X': ")
}
if(input=='X' | input=='x'){
exit -1
}
當我運行它(從命令行(UNIX))我得到這些結果:
> library("lattice")
>
> cat("Please enter the full path for your files, if you have no more files to add enter 'X': ")
Please enter the full path for your files, if you have no more files to add enter 'X': > fil<-readLines(con="stdin", 1)
x
> cat(fil, "\n")
x
> while (!input=='X' | !input=='x'){
+ inputfile=input
+ input<- readline("Please enter the full path for your files, if you have no more files to add enter 'X': ")
+ }
Error: object 'input' not found
Execution halted
我不太知道如何解決這個問題,但我很確定這可能是一個簡單的問題。 有什麼建議嗎? 謝謝!
@ttmaccer:您應該將其寫爲答案 – 2012-08-07 14:31:32
您可以嘗試使用'choose.files' – James 2012-08-07 14:33:27
@James您是否知道我可以找到如何使用choose.file的示例的地方? – Stephopolis 2012-08-07 14:34:55