A Better Example of the Confused By The Environment Issue

September 25, 2018

(This article was first published on R – Win-Vector Blog, and kindly contributed to R-bloggers)

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.


# unrelated value that happens 
# to be in our environment
z <- "y"

data.frame(x = 1, y = 2, z = 3) %>%
#   x y
# 1 1 2

data.frame(x = 1, y = 2) %>% # oops, no "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).

To leave a comment for the author, please follow the link and comment on their blog: R – Win-Vector Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)