I looked around and googled everything I could think of but cannot find a solution to what seems to be a basic problem. I am new to R, and I am working on a couple of projects, from various computers. Every time I open a project, I need to reinstall the various packages, and to activate them one by one with the library command. Is there a way to 'save' the installed packages and to save the active ones in the library of a project? thanks! Giulia
Asked
Active
Viewed 7,252 times
4
-
You can save a [workspace](https://www.statmethods.net/interface/workspace.html) and load it every time. – csgroen Jan 31 '18 at 19:43
-
6You should only need to run `install.pacakges` once per computer. But you do have to load them each time with `library()` What exactly are the errors you are getting that make you think you need to re-install? What type of "projects" are you using? Is this an Rstudio thing? – MrFlick Jan 31 '18 at 19:43
-
Possible duplicate: https://stackoverflow.com/questions/10300769/how-to-load-packages-in-r-automatically – MrFlick Jan 31 '18 at 19:45
-
2Possible duplicate of [How to load packages in R automatically?](https://stackoverflow.com/questions/10300769/how-to-load-packages-in-r-automatically) – doganak Jan 31 '18 at 20:04
-
This question is not a duplicate of [How to load packages in R automatically](https://stackoverflow.com/questions/10300769/how-to-load-packages-in-r-automatically). The problem is not that OP needs to load packages with `library()` repeatedly; that is fine. The problem is that OP must *reinstall* various packages repeatedly. – littleO May 27 '21 at 02:42
2 Answers
4
The packrat
package was made just for this (https://rstudio.github.io/packrat/). It allows you to create self cointained projects. Besides not having to install every package again this is desirable because even having different package verions could lead to having different results on each computer.

felasa
- 146
- 4
-
Nice package to check out! I sometimes add what `sessionInfo()` throws as a comment to my code when needed. – jay.sf Jan 31 '18 at 21:11
0
Install only Packages that are not already available in the system.
#Installing Packages that are not already available in the system
list.of.packages <- c("ggplot2","readr","magrittr","dplyr","lubridate","DataExplorer","gmailr","purrr","DT","plotly","shinycssloaders","rgdal","shinythemes","magrittr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)

Sudharsana Rajasekaran
- 320
- 3
- 12