I have a string that is built programmatically
tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10
that I need to wrap in two single quotes (without the double quotes on the string) and assign to an object mod:
# this is what I want
mod <- '
tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10
'
I've tried:
string <- "tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10"
mod <- as.symbol(paste("'", string, "'", sep=" ")) # to try and remove the double quotes
but mod gets wrapped in backtics
mod
`' tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10 '`
If more background would be helpful, please see a more detailed question I posted to the help group of the package I am using. I am posting a more specific question on SO because I've narrowed the problem to how the mod object is defined.
It does work if I use cat() and readLines():
string <- paste("'", "tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10", "'", sep=" ")
cat(string, file=paste0(string, ".lav"))
mod <- readLines(paste0(string, ".lav"))
but I don't think this should be necessary.