Trying to change a variable name of an XDF with rxSetVarInfo.
I want to merge several data sets with common var names. (I know rxMerge can/will append to filenames where needed. I want to have more control than that.)
This works:
outLetter<- "A"
exp <- list(pct.A = list(newName = paste0("X.pct.",outLetter)))
rxSetVarInfo(varInfo = exp, data = tempXDFFile)
That's where I know the original column name, pct.A
. What if that's dynamic? What if this is in a function that gets called several times with different outLetter
's. (The "A" isn't hardcoded.)
This does not work:
function(outLetter){
exp <- list(paste0("pct.",outLetter) = list(newName = paste0("X.pct.",outLetter)))
rxSetVarInfo(varInfo = exp, data = tempXDFFile)
}
Nor does:
exp <- parse(text = exp)
rxSetVarInfo(varInfo = exp, data = tempXDFFile)
Yes, I can hardcode all the permutations. Trying to find a more elegant approach.