I need to set an attribute on a data.frame, but I want to pass the data.frame name from a variable. I have tried several combinations of quote, substitute, parse, expression with no success. How it can be done?
#OK code
my_data_frame <- data_frame(col = 1:10)
attr(my_data_frame, "attr1") <- 1L
attributes(my_data_frame)
#Not OK code
df_name <- "my_data_frame"
attr(as.name(df_name), "attr2") <- 2L #this does not work
attr(quote(eval(df_name)), "attr2") <- 2L #this does not work
attr(parse(text = eval(df_name)), "attr2") <- 2L #this also don't work