0

Recently moved over to R (from MATLAB) - enjoying it…

…However, every time I close R down, I lose all the packages which I loaded in my previous session, and I need to load them up again (I use a Mac OS).

I know there is a way to save the current loaded packages, and have them load up automatically each time I reopen R - I have seen the answer in a few places, but I don't understand the terminology.

Can someone kindly walk me through it… Click by click?

With appreciation

smci
  • 32,567
  • 20
  • 113
  • 146
  • 1
    There's no click-y way to do this as far as I know. (Especially when you don't specify your GUI name version). But you can create a .Rprofile file in your home directory. When R starts up, it will look for that file and run the commands you have there. You can can use that opportunity to call `library()` to load whatever package you like. See the `?Startup` help page for these types of topics. – MrFlick Sep 05 '14 at 20:56
  • [Another guide for making your .Rprofile](http://www.statmethods.net/interface/customizing.html) in addition to link in the answer below – user20650 Sep 05 '14 at 22:57
  • @Moody_Mudskipper: it's possible to save the package list either with the Rsession, or in .Rprofile file. Of the two the latter seems a better recommendation for a new-user. – smci Feb 19 '18 at 04:55

1 Answers1

2

I do it with my .Rprofile file which resides in my default working directory. (I also un-hide my dot-files so it's easy to get at it.) I use Sys.setenv() to maintain the needed PATH environment variable and then load my packages with:

require(lattice)
require(sos)
require(rms)

Demonstrations of how to edit text-files and control of system resources are not really on-topic in SO. You should be able to teach yourself those skills by searching,

It's kind of amusing that one of the most highly voted R questions is closed as not constructive: Expert R users, what's in your .Rprofile? I will admit that technically it probably does violate the stated rules, but you may find it useful, both for the information and to see what sort of question is considered "on- (or off-)topic" in SO.

Community
  • 1
  • 1
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • 1
    +1 because it is the correct answer, but I would generally advise not to do that, as things will break when passing scripts to another computer or to someone else. Much better solution: save .R scripts with `library` calls in them. This will solve the library problem and has the huge bonus of helping your analysis to be reproducible. – nico Sep 05 '14 at 21:09
  • 1
    Your opinion was shared by several commenters at the link I provided. I see the main value of my "answer" as providing terminology to someone who appears to be in need of search strategies. I suspect that he didn't know that 'dot-files' (which some might call "system files") would be handled differently by Finder.app – IRTFM Sep 05 '14 at 21:13
  • again, i need a step by step solution… – Doron Howard Sep 05 '14 at 22:49
  • Again. StackOverflow is not in the business of crafting step-by-step solutions to people who don't have basic programming skills. We see no code that demonstrates you have made any effort. – IRTFM Sep 06 '14 at 01:12
  • look, i have done the programming i need to do... – Doron Howard Sep 06 '14 at 08:43
  • i am asking a simple question: how can i save the packages which are loaded, so i do not need to reload them next time... – Doron Howard Sep 06 '14 at 08:43
  • i am using Mac OS, i have my work saved, this is not a problem… I just want to know how to have R boot up next time with all the packages which are currently loaded, to avoid having to reload them (which takes about 30 seconds, but still…) – Doron Howard Sep 06 '14 at 08:47