It often takes a while to understand what is meant by " ... $
is a function which does not evaluate its second argument." Most R functions would take names(resB[[1]])
and eval;uate it and then act on the value. But not $
. It expects the second argument to be an actual column name but given as an unquoted string. This is an example of "non-standard evaluation". You will also see it operating in the functions library
and help
, as well as many functions in what is known perhaps flippantly as the hadleyverse, which includes the packages 'ggplot2' and 'dplyr'. The names of dataframe columns or the nodes of R lists are character literals, however, they are not really R names
in the sense that their values cannot be accessed with an unquoted sequence of letters typed to the console at the toplevel of R.
So as already stated you should be using d[[ names(resB[[1]]) ]]
. This is also much safer to use in programming, since there are often problems with scoping involved with the use of the $
-function in anything other than interactive console use.