R: Create environment in .Rprofile

172 Views Asked by At

When I use following snippet in my .Rprofile file of a project:

.env <- new.env()

.env$test <- function() {
  print("sfsdfsd")
}

and open the project in RStudio, ".env" isn't created:

ls(envir=.env) returns Error in ls(envir = .env) : object '.env' not found

.env$test() returns Error: object '.env' not found

Running the same code in RStudio is working though:

ls(envir=.env) then returns [1] "test"

Creating an environment via .RProfile file is recommended a lot (eg this blog post).

Has RStudio changed its behaviour?

0

There are 0 best solutions below