HI, I am rather new to R. I have written code in the past and my script works when I don't add the user input.I have 14 files in each of 2 txt file paths that have to be selected from. Each are specifically paired. the DS01 is paired with VDS1_1. I see the file path in the environment widow and it lists the files successfully. When I run it, I get no errors. But when I type in the DS01 in the interactive mode, I get the
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") : cannot open file 'DS1': No such file or directory
The interactive code is
{
askUser <- readline(prompt="Please, enter the data set (1-14) using DS# format: ")
SCpathname <<-"E:/Updated_Datasets_20190603/DS_textfiles/"
list.files(path = SCpathname, pattern = "txt")
VDSpathname <<-"E:/Updated_Datasets_20190603/VDS/"
list.files(path = VDSpathname, pattern = "txt")
print(askUser)
if (askUser== "DS01"){
SCfilename = "DS01"
VDSfilename = "VDS_DS1_1.txt"
SC120000 <- read.delim(file=SCfilename, header = FALSE)
VDS <- read.delim(file=VDSfilename, header=TRUE)
}else if (askUser== "DS02"){
SCfilename = " DS02"
VDSfilename = "VDS_DS2_1.txt"
SC120000 <- read.delim(file=SCfilename, header=FALSE)
VDS <- read.delim(file=VDSfilename, header=TRUE)
}else if (askUser== "DS03"){
SCfilename = " DS03.txt"
VDSfilename = "VDS_DS3_1.txt"
SC120000 <- read.delim(file=SCfilename, header=FALSE)
VDS <- read.delim(file=VDSfilename, header=TRUE)
}else if (askUser=="DS04" ){
SCfilename = " DS04.txt"
VDSfilename = "VDS_DS4_1.txt"
SC120000 <- read.delim(file=SCfilename, header=FALSE)
VDS <- read.delim(file=VDSfilename, header=TRUE)
}else {
return("Choose a different file number")
}
}
Before I had made it interactive, it was working exactly as it was suppose to performing dyplr mutate and ggplot2 operations. So it has to be something I am doing in the if then else statements . Also I am not married to this code. If someone has a way to make it so that askUser it can just use the numerical value in lapply or what have you I will use it. I just have had no success using lapply.