Our interference from then environment issue was a bit subtle. But there are variations that can be a bit more insidious.
Please consider the following.
library("dplyr") # unrelated value that happens # to be in our environment z <- "y" data.frame(x = 1, y = 2, z = 3) %>% select(-z) # x y # 1 1 2 data.frame(x = 1, y = 2) %>% # oops, no "z" select(-z) # x # 1 1 # notice column "y" was removed and # no error or warning was signalled.
When the data.frame
has a lot of columns, and is coming from somewhere else (even as an argument to a function): we may not notice the column loss until very much later (making for hard debugging or even unreliable results).
Categories: Opinion
jmount
Data Scientist and trainer at Win Vector LLC. One of the authors of Practical Data Science with R.
Hmmm… I have a bit different experience:
library(“dplyr”)
z % select(-z)
# Error in -z : invalid argument to unary operator
Same on my side, but I can reproduced the issue by defining
z <- 2
instead, and I admit this case can be quite confusing.It sounds like it may be senstive to package versions. And also I apologize to anybody who’s answer gets mangled by the comment system.
It works very well with dplyr version 0.7.6