[R] loading edited functions already in saved workspace automatically

Ralf Goertz r_goertz at web.de
Fri May 5 10:33:27 CEST 2017


Hi,

In short: Is it possible to have the previously saved workspace restored
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 gets
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.



More information about the R-help mailing list