Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load packages automatically when opening a project in RStudio

Tags:

r

rstudio

Every time I restart RStudio-it requires me to reload all of the packages that were loaded in the workspace previously. I can't seem to figure out what the problem is, RStudio is saving the projects when it closes them.

How can I make sure that RStudio reloads the necessary packages when I open the project?

like image 780
bwilliams18 Avatar asked Jan 09 '13 15:01

bwilliams18


People also ask

Do you have to load R packages every time?

You shouldn't have to re-install packages each time you open R. If library(dynlm) doesn't work without re-installing then I would say this is definitely an issue. However, you do generally need to load the packages you want to use in that session via library() .

How do you load data packages in R?

The default R datasets included in the base R distribution Simply check the checkbox next to the package name to load the package and gain access to the datasets. You can also click on the package name and RStudio will open a help file describing the datasets in this package.

How do I enable a package in R?

packages(' ') command. Alternatively, you would go to the packages field in Rstudio, click install packages, choose the package and click install. If you have the package on your computer, it is not ready to use yet. You need to attach/load/activate (synonyms) the package.


1 Answers

I presume you want to say that you have to reload all of the packages that were loaded in the workspace previously. That's not an error, that's by design.

If you want to load some packages at startup in a project, you can do so by creating a file called .Rprofile in the project directory, and specify whatever code you want RStudio to run when loading the project.

For example:

cat("Welcome to this project.\n")
require(ggplot2)
require(zoo)

would print a welcome message in the console, and load ggplot2 and zoo every time you open the project.

See also http://www.rstudio.com/ide/docs/using/projects

like image 154
Joris Meys Avatar answered Sep 20 '22 19:09

Joris Meys