Grig
Grig

Reputation: 119

is there a way to avoid having to install packages every time in R?

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

Upvotes: 4

Views: 8344

Answers (2)

Sudharsana Rajasekaran
Sudharsana Rajasekaran

Reputation: 328

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)

Upvotes: 0

felasa
felasa

Reputation: 145

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.

Upvotes: 4

Related Questions