Vesnič
Vesnič

Reputation: 375

Overwrite a function after loading .RData file

Let's say I have function

foo <- function (x, y){
    x <- y + 5
}

I save my work with save.image(file= file_name)

Then I load data with load(file, envir=.GlobalEnv)

Let's say I load the data, but after that I modify my function say:

foo <- function (x, y){
    x <- y + 10
}

If I run it, it will ignore my new version of function. Why does this happend and how to correct it?

Upvotes: 0

Views: 223

Answers (1)

Ferand Dalatieh
Ferand Dalatieh

Reputation: 353

It is working well with me and I couldn't find out why you can't overwrite your function. But here are some thoughts:

  • make sure that the new definition has same function name (in your case "foo").
  • definitely run the new definition (either in the console or using "RUN" in RStudio).
  • try using load(file) without determining the environoment. (in this case it will be envir = parent.frame()).

hope that could help :)

Upvotes: 0

Related Questions