Skip to content

Instantly share code, notes, and snippets.

@DarwinAwardWinner
Created January 11, 2020 17:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DarwinAwardWinner/5e9bd30dbf4ee1fb4e950838905235b9 to your computer and use it in GitHub Desktop.
Save DarwinAwardWinner/5e9bd30dbf4ee1fb4e950838905235b9 to your computer and use it in GitHub Desktop.
The environment setup for my R profile
local({
## Put everything in a separate environment and attach that
## environment. Re-use the existing one from the search path it
## it's available, so that re-executing this file doesn't add a
## new environment to the search path every time.
custom_env <- tryCatch(as.environment("rct_custom_env"),
error=function(...) {
attach(NULL, name="rct_custom_env")
as.environment("rct_custom_env")
})
## Now add anything you want to the environment, and it will now
## persist after clearing your workspace
custom_env$myfunc <- function(x) {
message("Called myfunc on:")
print(x)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment