[R] loading edited functions already in saved workspace automatically

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Fri May 5 15:30:01 CEST 2017

The answer most people seem to use is to avoid depending on functions in RData files, and in particular avoiding ever saving the "automatic" ".RData" files at all. (Some people avoid using any RData files, but the automatic loading of functions by ".RData" files is a particularly pernicious source of evil as you have already discovered.)

That is,  always work toward building scripts that you run to restore your workspace rather than depending on save files. Don't depend on save files to keep track of what you do interactively. This also usually means that there should be little if anything in your .Rprofile because that tends to build non-reproducibility into your scripts.
Sent from my phone. Please excuse my brevity.

On May 5, 2017 1:33:27 AM PDT, Ralf Goertz <r_goertz at web.de> wrote:
>In short: Is it possible to have the previously saved workspace
>and nevertheless load a function already existing in this workspace via
>.Rprofile anyway?
>In detail: I use different directories for different projects. In all
>those projects I use a function which I therefore try to get into the
>session by `myfunc=eval(parse(file=("~/R/myfunc.R")))' in ~/.Rprofile.
>Once I leave the session thereby saving the workspace this function
>saved in ./.RData as well. In a subsequent session in that directory it
>gets loaded back. However, in the meantime I might have edited
>~/R/myfunc.R. I don't seem to be able to automatically load the new
>function into the session. The workspace gets loaded *after* the
>execution of ~/.Rprofile. So the new definition of myfunc() gets
>overwritten by the old one. I can't use .First() – which is executed
>after loading the workspace – because this would load myfunc() into the
>environment of .First() instead of the global environment. I could use
>.Last() to remove the function before saving the workspace. But then
>.Last() gets saved to the workspace which is also not convenient since
>when I add another function the same way and edit the definition of
>.Last() in ~/.Rprofile to also remove that function this does not work
>because I don't get the new .Last() into the session automatically. And
>no, removing .Last() from within .Last() doesn't work.
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list