Reputation: 2192
I am trying to take two character vectors:
directory <- "specdata"
id <- 1
and read the data in from the file that they would "point" to: ie:
data <- read.table(paste(directory,"\\",id,".csv", sep="")
The problem is in the result of paste and the "\". I am trying to get it to return "specdata\1.csv"
however it returns "specdata\\1.csv"
which is not the same.
To no avail, I have also tried:
"\"
'\\'
'\'
'\'
'\\'
"\"
"\\"
code:
fileNameAndPath <- c(directory,"\",id,".csv")
data <- read.table(fileNameAndPath)
Upvotes: 12
Views: 15821
Reputation: 25736
You should use file.path
instead (it is independent of your platform):
file.path(directory, paste(id, ".csv", sep=""))
Upvotes: 23