tags:

views:

92

answers:

2

R allows us to put code to run in the beginning/end of a session.

What codes would you suggest putting there?

I know of three interesting examples (although I don't have "how to do them" under my fingers here):

  1. Saving the session history when closing R.
  2. Running a fortune() at the beginning of an R session.
  3. I was thinking of having an automated saving of the workspace. But I didn't set on solving the issue of managing space (so there would always be X amount of space used for that backup)

Any more ideas? (or how you implement the above ideas)

p.s: this is continuing a thread started on "stat.overflow"

+1  A: 

I am pretty sure we had a question like this here before. See eg http://stackoverflow.com/questions/1189759/expert-r-users-whats-in-your-rprofile or more generally search for "[r[ Startup" or other appropriate tags.

Dirk Eddelbuettel
Nice Dirk - thank you!
Tal Galili
+2  A: 

Apart from .Rprofile, you could define .First and .Last functions. I usually put graphics.off() to get rid of any graphic displays running, so, in this case, it should go something like this:

.Last <- function() {
    graphics.off()
    save.image()  # optionally, you can define specific file/folder
    system(paste("cowsay", "Goodbye @ ", date()))  # if you're running GNU/Linux

and get something like this:

 ___________________________________ 
< Goodbye @ Wed Aug 4 22:49:46 2010 >
 ----------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

However, this ain't much useful. While .Rprofile manages R start-up, .Last function can perform various operations "on exit"... like saving image file or so...

aL3xa