Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: I am not sure if to put this here or on stackoverflow. But I feel the people here are the right ones to ask.

share|improve this question
Probably better suited to stackoverflow since it has no particular data analysis relevance. – Shane Aug 3 '10 at 8:28
This question is proposed to be closed. See this meta thread:… – user28 Aug 3 '10 at 8:58
I wish we could move a question to Stack Overflow the way you can move a question from Super User... – JD Long Aug 3 '10 at 20:42
I moved it manually to stackoverflow. JD - I agree with you. – Tal Galili Aug 4 '10 at 20:14
Following on from… I've reopened this question. – csgillespie Aug 11 '10 at 10:43

Some information about how to implement this is provided at help(.First) and help(.Last).

share|improve this answer

On open, I set R options, load environment variables (eg. global variables, API keys) and open database connections, and then close those connections when exiting. With some of these things, I prefer to do them onLoad of my packages rather than per session.

Regarding how to save your session, use the save command.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.