Where are the installed R packages? [duplicate] - r

This question already has answers here:
Where does R store packages?
(4 answers)
Closed 8 years ago.
Where are the installed R packages?
For example, after installing packages with 'install.packages("mlbench")' and so on, only "The downloaded binary packages are in C:\Users\ABC\AppData\Local\Temp\Rtmp2XB0sh\downloaded_packages" is a piece of related info from the console messages.
However, I fail to find them at all after scouring my computer according to package names (not just listing them with 'installed.packages()'). This question seems very difficult for me, but strangely I found almost no answer online. Where are the installed packages on the local computer?

You can view the location by running the following:
.libPaths()
#[1] "C:/Users/ujjwal/Documents/R/win-library/3.1" "C:/Program Files/R/R-3.1.1/library"
R packages are installed into libraries, which are directories in the file system containing a subdirectory for each package installed there.
R comes with a single library, R_HOME/library which is the value of the R object .Library containing the standard and recommended packages. At the lowest level .libPaths() can be used to add paths to the collection of libraries or to report the current collection.
R will automatically make use of a site-specific library R_HOME/site-library if this exists. This location can be overridden by setting .Library.site in R_HOME/etc/Rprofile.site. For more details see here.

Related

Local libraries path removed from R path after minor upgrade [duplicate]

This question already has answers here:
R 3.4.1 "Single Candle" Personal Library Path Error: unable to create ‘NA’
(6 answers)
Closed 5 years ago.
I have a lot of packages installed in ~/R/x86_64-pc-linux-gnu-library/3.4/. Today, I opened R, and attempted to run some code, and I found that packages were not being recognised:
Error in library("some_package"): there is no package called ‘some_package’
I looked at the paths, and I got this:
.libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library" "/usr/lib/R/library"
which explains why packages are not longer recognised. Now, I know how to solve this (add local path to R paths, e.g. modifying /etc/R/Renviron).
Notice that I updated R via sudo apt-get update.... However, the update was minor (from 3.4 to 3.4.1) (so this is not a duplicate of this question). Here is the command line output of the update/upgrade. It seems the issue might have been related to the update of /etc/R/Renviron, as the line Replacing config file /etc/R/Renviron with new version indicates.
My packages source is
deb https://cloud.r-project.org/bin/linux/ubuntu xenial/
My question is, why did this change happen? Does every minor change in R restores the paths to default? Is it somewhere explained in some documentation? I can't find a warning about it here or elsewhere.
It's related to 3.4.1's new(?) default behaviour of making the same library of R packages available to all users on your Linux system. See here for a neat solution: https://stackoverflow.com/a/44903158/4115816
(The thread also describes some other options.)

cannot install plyr package in R [duplicate]

This question already has answers here:
How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning?
(18 answers)
Closed 8 years ago.
I tried installing the plyr package and I got the warning message saying it isn't available for R version 3.0.2. Is this true or is no? If not, why would I be getting this message? I tried using two different CRAN mirrors and both gave the same message.
The answer is that the package is available in R (just checked this on my machine).
The particular error message that you are getting is very misleading. It is R's `catch-all' condition for anything that it doesn't understand going wrong during installation. You will get this error if you mis-spelled anything (Plyr instead of plyr) or your network connection is not working, or you are behind a proxy or whatever.
I typically get this problem when I am behind a proxy or I have mis-spelled something. But it can be because of any other number of reasons. I will suggest you make sure you can access the internet from inside R first.
If nothing works, you can always download the package from CRAN using a browser. If you are on Windows, you want the .zip version and if you are on *nix you want the .tar.gz version. (.tgz for Macs?). Then you can install it like so:
setwd("/path/where/I/downloaded/the/compressed/file")
install.packages("plyr", repos=NULL)
See if that works.

installed directory not writable, cannot update packages 'boot', 'class', 'KernSmooth', 'mgcv', 'nnet', 'rpart', 'spatial' [duplicate]

This question already has answers here:
installation path not writable R, unable to update packages
(9 answers)
Closed 2 years ago.
I installed the Bioconductor packages on R version 3.1.2 on Ubuntu 14.04 and received the message below:
The downloaded source packages are in
‘/tmp/RtmpZYw0Qp/downloaded_packages’ Warning message: installed
directory not writable, cannot update packages 'boot', 'class',
'KernSmooth', 'mgcv', 'nnet', 'rpart', 'spatial'
What does it mean, and how does it affect using the above packages on R?
I faced the same problem working in R-studio. The solution is to give root access to R.
In Windows, that means you need to run the program as an Administrator.
In Unix/Linux, you should launch R from the terminal by doing sudo R.
Then, once you're running with sufficient privileges, you can try installing your package and it should work.
The warning means that there are more recent versions of the listed packages available, but your version cannot be updated because the directory in which the packages are installed cannot be written to. Usually this means that R was installed with 'system administrator' privileges, but that you are trying to update packages as a regular user.
The consequence is that the features or bug fixes implemented in the updated packages are not available to you. The specific consequences could range from minor typographical corrections on a man page through serious bug fixes. Qualitatively, my bet is that it 'does not matter' for most uses.
The solution is to update these packages when running R as a user with permission to write to packages in the installed directories -- typically the last element of the output of .libPaths(), or more fine-grained via installed.packages()[, "LibPath"]
I faced the same problem today when installing three Bioconductor packages under Windows. Two (dependencies of the package I really wanted) were already on my system in newer forms (as described in #Martin-Morgan solution) and so no action was necessary. However, one was not installed. For this, third package, I had success in doing an installation from the local file that was downloaded during the failed install without having to escalate privileges (which was my next step as outlined by #Ninadmw).
In R, go to the menu Packages/Install Package(s) from local files and navigate to the local download directory listed, which in your case was /tmp/RtmpZYw0Qp/downloaded_packages, and select the package you want to install.
In RStudio (which you should use), go to the menu Tools\Install Packages, change the install from field to Package Archive File (.zip; .tar.gz), use Browse... to navigate to the listed download directory, which in your case was /tmp/RtmpZYw0Qp/downloaded_packages and select the package you want to install. Then click on the Install button.

binary packages not available after update R to 3.1.2 [duplicate]

This question already has answers here:
How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning?
(18 answers)
Closed 8 years ago.
I have just updated R to version 3.1.2, and many packages seem not yet available, such as RmySQL.
What can I do? Uninstall the latest version of R and go back to version 3.0? Or are there other ways?
The problem is especially related to Apple, although for some packages (eg RMySQL) this problem can occur in Windows as well.
On Apple, you can try to install from source:
install.packages('plotGoogleMaps', type='source')
Note that with RMySQL you also have to make sure your environment variables are set correctly. You find more info on the installation procedure on their CRAN page.
On Windows, you need to install Rtools before you can install from source:
http://cran.r-project.org/bin/windows/Rtools/
After you've done that, you can use the same option as above.
Be warned though that building from source might require a manual configuration of your system. This is the case for both rgeos and RMySQL. Information on these procedures can be found on the CRAN page of either package:
eg for rgeos you need to preinstall GEOS as specified in the system requirements:
http://cran.r-project.org/web/packages/rgeos/index.html
For RMySQL you need to set up yor environment variables, as specified here:
http://cran.r-project.org/web/packages/RMySQL/INSTALL
EDIT: Building on MAC
If you want to build binary packages on Mac machines, you need to take into account that you might need extra tools, especially when these packages contain compiled code. This is explained in more detail in the R FAQ for Mac and the Administration and Installation manual:
http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Installation-of-source-packages
http://cran.r-project.org/doc/manuals/r-release/R-admin.html#OS-X
Alternatively, you might want to check the R for MAC's Developer page at http://r.research.att.com/ This one contains more information on the toolchain you need.

get functions from old package [duplicate]

This question already has answers here:
extracting source code from r package
(2 answers)
Closed 8 years ago.
There are a number of packages that have functions I would like to use, however these packages are no longer maintained and were built for older R versions.
Using R 3.0.02 I get the following
install.packages("steepness")
Warning message:
package ‘steepness’ is not available (for R version 3.0.2)
Similarly using
packageurl <- "http://cran.r-project.org/src/contrib/Archive/steepness/steepness_0.2.tar.gz"
install.packages(packageurl, contriburl=NULL, type="source")
Warning message:
package ‘http://cran.r-project.org/src/contrib/Archive/steepness/steepness_0.2.tar.gz’ is not available (for R version 3.0.2)
and when i manually place the steepness folder in the win-library:
library(steepness)
Error: package ‘steepness’ was built before R 3.0.0: please re-install it
I only want a couple functions to save myself time rewriting everything from scratch. What is the best way round this? Can I just copy the source code for the two functions myself for example and define them myself? I have looked at the folder for the package but there is no obvious .r file to steal code from ONLY .rdb AND .rdx which are file formats I am not familiar with.
If you have some experience with defining functions in R you can just download the bundled *.tar.gz package from CRAN, look in the R folder of the unpacked package and extract the code you need.

Resources