assigning a string to an object without double quotes

前端 未结 2 884
醉话见心
醉话见心 2021-01-23 16:45

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

2条回答
  •  无人及你
    2021-01-23 17:36

    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
    

提交回复
热议问题