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

Environments as Variables #22

Open
jonthegeek opened this issue Jun 1, 2020 · 1 comment
Open

Environments as Variables #22

jonthegeek opened this issue Jun 1, 2020 · 1 comment
Labels
wontfix This will not be worked on

Comments

@jonthegeek
Copy link
Owner

library(factory)

# Define the function the normal way.
get_x <- function() {
  get("x", .GlobalEnv)
}
get_x
## function() {
##   get("x", .GlobalEnv)
## }

# Note that it shows ".GlobalEnv". It works even if I kill the srcref.
attr(get_x, "srcref") <- NULL
get_x
## function () 
## {
##     get("x", .GlobalEnv)
## }

# Building from a factory shows <environment> instead of .GlobalEnv
get_from_env <- build_factory(function() get(.x, .env), .x, .env)
get_x <- get_from_env("x", .GlobalEnv)
get_x
## function () 
## get("x", <environment>)

Perhaps something to look at either in the way the factory is evaluating its inputs, or maybe in rlang itself.

@jonthegeek
Copy link
Owner Author

An interesting tip: This works, and displays as the original:

get_x <- get_from_env("x", quote(.GlobalEnv))

This bug has something to do with the arguments being evaluated as the function is created. It's related to another thing I was seeing with the .internal_variables code I added recently.

For now I'm gonna tag this with won't fix, unless something related comes up (such as maybe #28).

@jonthegeek jonthegeek added the wontfix This will not be worked on label Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant