hadley / adv-r

Advanced R: a book
http://adv-r.hadley.nz
Other
2.36k stars 1.71k forks source link

`Error in `$`(x, eval(var)) : invalid subscript type 'language'` #1777

Open danli349 opened 1 year ago

danli349 commented 1 year ago

Thanks for the excellent book! Could you please let me know what is wrong with my code? Thanks.

x <- list(var = 1, y = 2)
var <- "y"
eval(var)
x$var
`$`(x, var)
`$`(x, "var")

x[[var]]
`$`(x, "y")
`$`(x, eval(var))
[1] "y"
[1] 1
[1] 1
[1] 1
[1] 2
[1] 2
Error in `$`(x, eval(var)) : invalid subscript type 'language'