Standardizing Non-standard Evaluation in R
"Partway through her LTER Postdoc at SESYNC, ecologist Meghan Avolio ran into trouble manipulating her data on plant communities with dplyr functions. I had encouraged Meghan to modularize her scripts by writing functions for common steps in her pipeline (such as converting count data into rank-abundance curves). “You’ll love writing functions!” I said wrongly.
Meghan quickly ran up against the trickery of non-standard evaluation (NSE) as employed by most of the dplyr functions. In calls to mutate, filter, group_by and friends, column names are supplied without quotation marks. An expression like mutate(df, rank = rank(abund)) fails when abund is not literally a column in the data frame. And how could you possibly know the column names in a function that handles arbitrary data frames?"
Read the complete post on SESYNC's new Cyberhelp blog.