How can I convert a character string such as "c(1:10)"
into an actual vector of integers? My issue is that I need to read a bunch of files using read.xlsx
from the package xlsx, but I need to read different rows for each file. I've got a separate file that I can read into the workspace as a data.frame (call it "MyFile") that lists in one column the names of the files and, in another column, which rows to read, but I don't know how to convert the character string into the numbers I need. I'd use regex to extract it, but that sounds like more work than I want since it's a mishmash of everything from "c(1:10)"
to "c(2, 4, 6:8, 21)"
.
I've tried:
Files <- list()
for (i in 1:nrow(MyFiles)){
Files[[i]] <- read.xlsx(MyFiles$File[i],
sheetName = MyFiles$Tab[i],
rowIndex = MyFiles$Row[i])
}
but R doesn't know what to do with the row specification since it's currently reading it as a character string.