1

I've been struggling for a while with this : I try to use a variable which is built in the global environnement inside my function code.

Here is my code :

adressbrouillon="C/Data/..."
load_all <- function() {
load(paste(adressbrouillon,"work.RData",sep=""))
}

When I run :

load_all()

Nothing happens.

However, when I run this command :

load(paste(adressbrouillon,"work.RData",sep=""))

That's works very well!

Can anyone tell me what's happen and what to do to get my load_all function work? Thanks in advance!

hans glick
  • 2,431
  • 4
  • 25
  • 40

1 Answers1

3

Try this:

load_all <- function() {
    load(paste(adressbrouillon,"work.RData",sep=""), envir = .GlobalEnv)
}

If you don't specify envir, the data is loaded into a temporary environment which is destroyed when the function returns.

Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61