Search code examples
reval

'Error in !`*tmp*` : invalid argument type' error when using !! operator in R


I am trying to programmatically initialize some variables in R so that the variable name would be the evaluated content of the string.

Just this code:

library(dplyr)

v <- 'sum.of.ranfx'
new_v = sym(v)

!!new_v <- vector(mode = "list", length = 122)

fails with

Error in !`*tmp*` : invalid argument type

Google gives me no hits for this exact error. Here is an example accepted and upvoted SO answer whose syntax example I think I am following. Can you tell me what I'm doing wrong?


Solution

  • You may use assign -

    v <- 'sum.of.ranfx'
    assign(v, vector(mode = "list", length = 122))