Soren Christensen
Soren Christensen

Reputation: 376

Changeing directory in R studio when installing packages

How do i choose the library which the package is install in in Rstudio?

When i run "install and restart" i get this error:

installing to library 'C:/Program Files/R/R-4.0.0/library'
Error: ERROR: no permission to install to directory 'C:/Program Files/R/R-4.0.0/library'
Exited with status 1.

I want it to install on "h:/r_packages"

Upvotes: 0

Views: 590

Answers (3)

Robert
Robert

Reputation: 1028

When using withr::with_libpaths a lot of related packages also get installed in the specified folder. If you just want to install the package in a specific folder use this command:

devtools::install(args = c('--library=path/to/directory'))

Upvotes: 0

Stéphane Laurent
Stéphane Laurent

Reputation: 84529

As I understand you want to install your personal package. I don't find any option for the library path in RStudio. You can run this code in the console:

withr::with_libpaths("h:/r_packages", devtools::install())

You have to run this command when the current directory is the one of the package. Otherwise use the pkg argument of devtools::install to specify the package directory.

Upvotes: 1

Kota Mori
Kota Mori

Reputation: 6740

The second argument of install.packages is lib, which specifies the library directory. The help reads:

lib 

character vector giving the library directories
where to install the packages.
Recycled as needed.
If missing, defaults to the first element of .libPaths().

So, the below would work, though I cannot try on my end.

install.packages("package_name", lib="h:/r_packages")

Upvotes: 0

Related Questions