Changing libpath in R does not take effect - r

Am trying to change the .libpaths() in R
Currently I see the below two paths
.libPaths()
[1] "C:/Program Files/R/R-4.0.5/library"
[2]
"C:/Users/test/AppData/Local/Temp/Rtmpkj8NNm/renv-system-library"
However, I would like to retain only the 1st libpath
So, I tried the below
myPaths <- c("C://Program Files//R//R-4.0.5//library")
.libPaths(myPaths)
.libPaths()
But still I see both the paths as output
.libPaths()
[1] "C:/Program Files/R/R-4.0.5/library"
[2] "C:/Users/ephssmk/AppData/Local/Temp/Rtmpkj8NNm/renv-system-library"
Can help me retain only the 1st path as .libpaths()?
If temp folder should definitely be there in .libpaths, why is it storing under renv-system-library?

What you're seeing is the renv sandbox library. It's discussed a bit in the FAQ, as well as in ?renv::config, but it probably deserves some more documentation elsewhere.
https://rstudio.github.io/renv/articles/faq.html
That said, I'm a little confused. It looks like you're trying to use renv with a project, but you want to change the library paths so that the renv library path isn't actually used? You can probably use renv::deactivate() to disable renv in that project, then re-launch R.

Related

How can I find readxl and Rcpp files that I downloaded in the Drive C? [duplicate]

The install.packages() function in R is the automatic unzipping utility that gets and install packages in R.
How do I find out what directory R has chosen to store packages?
How can I change the directory in which R stores and accesses packages?
The install.packages command looks through the .libPaths() variable. Here's what mine defaults to on OSX:
> .libPaths()
[1] "/Library/Frameworks/R.framework/Resources/library"
I don't install packages there by default, I prefer to have them installed in my home directory. In my .Rprofile, I have this line:
.libPaths( "/Users/tex/lib/R" )
This adds the directory /Users/tex/lib/R to the front of the .libPaths() variable.
This is documented in the 'R Installation and Administration' manual that came with your installation.
On my Linux box:
R> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
[3] "/usr/lib/R/library"
R>
meaning that the default path is the first of these. You can override that via an argument to both install.packages() (from inside R) or R CMD INSTALL (outside R).
You can also override by setting the R_LIBS_USER variable.
Thanks for the direction from the above two answerers. James Thompson's suggestion worked best for Windows users.
Go to where your R program is installed. This is referred to as R_Home in the literature. Once you find it, go to the /etc subdirectory.
C:\R\R-2.10.1\etc
Select the file in this folder named Rprofile.site. I open it with VIM. You will find this is a bare-bones file with less than 20 lines of code. I inserted the following inside the code:
# my custom library path
.libPaths("C:/R/library")
(The comment added to keep track of what I did to the file.)
In R, typing the .libPaths() function yields the first target at C:/R/Library
NOTE: there is likely more than one way to achieve this, but other methods I tried didn't work for some reason.
You do not want the '='
Use .libPaths("C:/R/library") in you Rprofile.site file
And make sure you have correct " symbol (Shift-2)

Remove path from .libPaths() so just a single non standard path is left as library

I want to have a single library in R, which is not the default.
The idea is, to push the needed Rprofiles or environment variables out to all network computers, such that all use the same R-respository.
I added an environment variable to add the new lib, but I can't figure out how to get rid of the standard library. I don't know how to edit the Rprofile.
> Sys.getenv("R_LIBS_USER")
[1] "X:/R Repository Database"
> Sys.getenv("R_LIBS")
[1] "X:/R Respository Database"
> .libPaths()
[1] "X:/R Repository Database" "C:/ProgramFiles/R/R-3.2.5/library"
You can't change the system setting for the package directory ($R_HOME/library), nor should you. That directory contains the packages that come with R, including the base package, and it's likely that R would fail to start correctly if you tried pointing it elsewhere.
But this is really a distraction. The main sources of incompatibilities come from using different versions of user-contributed packages. Those you can control by having a site-wide package directory, which is what you've done. Incompatibilities due to different versions of system packages are really down to using different versions of R; if you want to avoid those, then install only one R version.

How to properly set up the library directory/path in R

My goal is to define a single path which R will use for installing and searching for libraries. I read that this can be done by changing the Rprofile.site file in the R installation path. I tried two commands there:
.libPaths("D:/RLibrary")
.Library.site <- file.path("D:/RLibrary")
of which I do not fully understand the difference even after reading the help files.
However after starting R, libraries are still looked for in two locations.
.libPaths()
[1] "D:/RLibrary" "C:/Program Files/R/R-3.3.1/library"
Why is this, and how do I change the library path to my desired path only?
I would suggest you don't want a single directory for packages, since a number of base packages come with R. Instead you want a single directory where a user will install packages.
Create a .Renviron file and add the environment variable R_LIBS pointing to the directory you want your packages to end up in. On my machine, I have
# Linux
R_LIBS=/data/Rpackages/
Or if you have Windows something like
# Windows
R_LIBS=C:/R/library
Your .libPaths() would now look something like
R> .libPaths()
[1] "/data/Rpackages" "/usr/lib/R/site-library"
This means that when I install a package it goes to /data/ncsg3/Rpackages
If you really want to only have a single directory, you can set the R_LIBS_SITE variable to omit the default directories.

R package installation location on windows [duplicate]

The install.packages() function in R is the automatic unzipping utility that gets and install packages in R.
How do I find out what directory R has chosen to store packages?
How can I change the directory in which R stores and accesses packages?
The install.packages command looks through the .libPaths() variable. Here's what mine defaults to on OSX:
> .libPaths()
[1] "/Library/Frameworks/R.framework/Resources/library"
I don't install packages there by default, I prefer to have them installed in my home directory. In my .Rprofile, I have this line:
.libPaths( "/Users/tex/lib/R" )
This adds the directory /Users/tex/lib/R to the front of the .libPaths() variable.
This is documented in the 'R Installation and Administration' manual that came with your installation.
On my Linux box:
R> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
[3] "/usr/lib/R/library"
R>
meaning that the default path is the first of these. You can override that via an argument to both install.packages() (from inside R) or R CMD INSTALL (outside R).
You can also override by setting the R_LIBS_USER variable.
Thanks for the direction from the above two answerers. James Thompson's suggestion worked best for Windows users.
Go to where your R program is installed. This is referred to as R_Home in the literature. Once you find it, go to the /etc subdirectory.
C:\R\R-2.10.1\etc
Select the file in this folder named Rprofile.site. I open it with VIM. You will find this is a bare-bones file with less than 20 lines of code. I inserted the following inside the code:
# my custom library path
.libPaths("C:/R/library")
(The comment added to keep track of what I did to the file.)
In R, typing the .libPaths() function yields the first target at C:/R/Library
NOTE: there is likely more than one way to achieve this, but other methods I tried didn't work for some reason.
You do not want the '='
Use .libPaths("C:/R/library") in you Rprofile.site file
And make sure you have correct " symbol (Shift-2)

Where does R store packages?

The install.packages() function in R is the automatic unzipping utility that gets and install packages in R.
How do I find out what directory R has chosen to store packages?
How can I change the directory in which R stores and accesses packages?
The install.packages command looks through the .libPaths() variable. Here's what mine defaults to on OSX:
> .libPaths()
[1] "/Library/Frameworks/R.framework/Resources/library"
I don't install packages there by default, I prefer to have them installed in my home directory. In my .Rprofile, I have this line:
.libPaths( "/Users/tex/lib/R" )
This adds the directory /Users/tex/lib/R to the front of the .libPaths() variable.
This is documented in the 'R Installation and Administration' manual that came with your installation.
On my Linux box:
R> .libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"
[3] "/usr/lib/R/library"
R>
meaning that the default path is the first of these. You can override that via an argument to both install.packages() (from inside R) or R CMD INSTALL (outside R).
You can also override by setting the R_LIBS_USER variable.
Thanks for the direction from the above two answerers. James Thompson's suggestion worked best for Windows users.
Go to where your R program is installed. This is referred to as R_Home in the literature. Once you find it, go to the /etc subdirectory.
C:\R\R-2.10.1\etc
Select the file in this folder named Rprofile.site. I open it with VIM. You will find this is a bare-bones file with less than 20 lines of code. I inserted the following inside the code:
# my custom library path
.libPaths("C:/R/library")
(The comment added to keep track of what I did to the file.)
In R, typing the .libPaths() function yields the first target at C:/R/Library
NOTE: there is likely more than one way to achieve this, but other methods I tried didn't work for some reason.
You do not want the '='
Use .libPaths("C:/R/library") in you Rprofile.site file
And make sure you have correct " symbol (Shift-2)

Resources