我对 R 有点陌生,并且对我正在尝试编写的程序有疑问。我希望通过一个while循环(最终在每个文件上使用read.table)来接收文件(用户喜欢多少),但它一直在困扰着我。这是我到目前为止所拥有的:
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
我不太确定如何解决这个问题,但我很确定这可能是一个简单的问题。有什么建议么?谢谢!