How to set a specific attribute of an object if the object name is in a variable?

Viewed 130

Normally you would set the attribute of an object as

attributes(x) <- list(dummy = 123)

But I have the variable names stored in a character vector. The following code throws an error:

var <- "x"
attributes(eval(as.name(var))) <- list(dummy = 123)

Error in attributes(eval(as.name(var))) <- list(dummy = 123) : could not find function "eval<-"

If eval(as.name()) is not the right way could someone suggest a way to solve this problem?

1 Answers
Related