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

New feature: Recognize functions that modify the parent environment? #62

Open
jcrodriguez1989 opened this issue Aug 20, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@jcrodriguez1989
Copy link
Owner

For example, when opt_constant_propagation finds a function call, it deletes the previously found constant-assigned values. This is mainly done to avoid having

x <- 1
assign("x", 3)
y <- x

Propagated to

x <- 1
assign("x", 3)
y <- 1

In R we can list which base functions modify the environment, for example, assign, rm, etc. However, this would not be a solution, as we can define new functions that wrap the base ones, for instance:

rm_all <- function() {
env <- .GlobalEnv
rm(list = ls(envir = env), envir = env)
}

A possible solution would be to let the user identify which functions edit the environment.

  • in a roxygen2 way:
# o @edits_env rm_all
...

or

rm_all() # o @edits_env
  • by parameter:
opt_constant_propagation(list(code), env_edit = c("rm_all", ...))
@jcrodriguez1989 jcrodriguez1989 added the enhancement New feature or request label Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant