Created
January 11, 2020 17:32
-
-
Save DarwinAwardWinner/5e9bd30dbf4ee1fb4e950838905235b9 to your computer and use it in GitHub Desktop.
The environment setup for my R profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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