Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A subtle scoping flaw in pull() #7064

Open
graphdr opened this issue Aug 1, 2024 · 0 comments
Open

A subtle scoping flaw in pull() #7064

graphdr opened this issue Aug 1, 2024 · 0 comments

Comments

@graphdr
Copy link

graphdr commented Aug 1, 2024

If x is not a column name in data frame d, then pull(d, x) attempts to look up the value of x in the environment instead of returning NULL or an error as I would expect.

library(dplyr)

# Create two env-variables
d <- data.frame(x = "ex", y = "why")
x <- "y"

# As expected, pulls the data-variable `x`
pull(d, x)

# If name `x` does not exist in `d`,
d <- select(d, -x)

# Not expected: finds the env-variable `x`, pulls the data-variable `y`
pull(d, x)

# Exactly as if we had written pull(d, y)
identical(pull(d, x), pull(d, y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant