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 si
I think you are misunderstanding R string syntax. The string you described is:
# this is what I want
mod <- '
tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10
'
That is exactly the same as writing:
mod <- '\ntot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10\n'
or
mod <- "\ntot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10\n"
Therefore, for your problem I think it would be sufficient to run:
string <- "tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10"
mod <- paste0("\n", string, "\n")
If you want to output your final model without the enclosing quotes, you can do:
cat(mod)
#
# tot=~item1+item2+item3+item4+item5+item6+item7+item8+item9+item10