我对R相当陌生。我过去写过代码,当我不添加用户输入时我的脚本也起作用。我必须从2个txt文件路径中选择14个文件。每个都专门配对。 DS01与VDS1_1配对。我在环境寡妇中看到文件路径,它成功列出了文件。运行它时,没有任何错误。但是当我在交互模式下输入DS01时,我得到DS01对象不存在错误。
{
askUser <- readline(prompt="Please, enter the data set (1-14) using DS# format: ")
SCpathname <-"E:/DS_textfiles/"
list.files(path = SCpathname, pattern = "txt")
VDSpathname <<-"E:/VDS/"
list.files(path = VDSpathname, pattern = "txt")
# to show the path works and files are there
print(askUser)
if (askUser== DS01){
SCfilename = "DS01.txt"
VDSfilename = "VDS1_1.txt"
SC120000 <- read.table(file=SCfilename, header=FALSE)
VDS <- read.table(file=VDSfilename, header=TRUE)
}else if (askUser== DS02){
SCfilename = " DS02.txt"
VDSfilename = "VDS2_1.txt"
SC120000 <- read.table(file=SCfilename, header=FALSE)
VDS <- read.table(file=VDSfilename, header=TRUE)
}else if (askUser== DS03){
SCfilename = " DS03.txt"
VDSfilename = "VDS3_1.txt"
SC120000 <- read.table(file=SCfilename, header=FALSE)
VDS <- read.table(file=VDSfilename, header=TRUE)
}else if (askUser==DS04 ){
SCfilename = " DS04.txt"
VDSfilename = "VDS4_1.txt"
SC120000 <- read.table(file=SCfilename, header=FALSE)
VDS <- read.table(file=VDSfilename, header=TRUE)
}else {
return("Choose a different file number")
}
}