Manually Downloading and Installing Packages in R - r

I am currently trying to run some R code on a computing cluster but cannot run the install.packages function due to some weird firewall settings on my cluster. Since I am only using a few packages in my R code, I was hoping to avoid using the install.packages function by downloading and installing the packages manually.
Note: I am aware that there is a way to avoid this issue by using an HTTP proxy as described in the R FAQ. Unfortunately the people in charge of my cluster are not being helpful in setting this up so I'm forced to consider this alternative approach.
Ideally, I would like to download the packages files from CRAN to my computer, then upload these files to the cluster and install them using the appropriate commands in R. In addition, I would also like to make sure that the packages are installed to a location of my choice since I do not have the permission to "write" in the default R directory (I believe that I can do this within R by using the .libPaths function)
Lastly, the computers that I am working with on the cluster are Unix x86_64.

You can install the package manually using the following command
install.packages('package.zip', lib='destination_directory',repos = NULL)
See the help of ?install.packages, for further description

I also went through the same problem while installing the caret package. There are many dependencies of the caret package.
So, I did the following:
install.packages('caret'):
This gives all packages in zip format the location of download is shown in the error message. Unzip all packages from download source to a location for example in C:/PublicData/RawRPackages, then run following command.
foldername <- 'C:/PublicData/RawRPackages'
install.packages(paste(foldername, 'caret', sep = '/'),
repos = NULL, type = "source")
library(caret, lib.loc = foldername)

this the better way, if we want to download and install locally :
download.packages('lib_name',destdir='dest_path')
for example :
download.packages('RJDBC',destdir='d:/rlibs')

install.packages("libname",lib = "file://F:/test")

Related

Is there a way to 'install' R packages without running install.packages()?

We are testing how to run R in the cloud in a secure isolated environment that is blocked from CRAN and also cannot use packages.install(). We defined an environment which is based on R essentials Anaconda's bundle, still we would like to be able to customize it on demand with extra packages. Is there a way to be able to simulate packages.install(), e.g. by offline downloading the package, zip it, copy to the secure environment and unzipping it to a specific location in the library folder?
thanks!
You can download the package from CRAN as a zip and then transport it to the isolated PC as a file. For example, here is the link to dplyr on CRAN: https://cran.r-project.org/web/packages/dplyr/index.html
Then use the code below to install the local file:
install.packages("~/Downloads/dplyr_1.0.7.zip", repos = NULL)
On Windows you might require Rtools. At least there was a Warning about it but the package still installed.
For Linux machines, you can build the package from source using the tarball from the same page:
install.packages("~/Downloads/dplyr_1.0.7.tar.gz", repos = NULL, type = "source")
In both cases you need to take care of dependencies yourself as they are not checked while installing through this method (look at the "imports" field on the CRAN website for the package).

R: Error in install.packages : cannot open the connection

I was trying to install the package RINDSEL but I am unable to install it and I keep getting the following error:
Error in install.packages : cannot open the connection
I downloaded the package from:
rindsel_1.0_2.zip | Integrated Breeding Platform
and loaded it from the directory. Other packages from the directory can be installed but just not this one.
Is the package corrupt or could there be any other error?
I would really be grateful for any help. Thanks in advance
Rename the zip file RinSel Software into Rindsel. That's the name specified in the discription file.
Then, you can install the package in R with the command
install.packages("C:/path/to/Rindsel.zip",repos=NULL,type="win.binary")
That works fine... at first (!!!).
Problem with the Rindsel package is. It is quite old. It was build with R 2.13.1. Therefore, if you want to load the library which would be the next step to use the package in R you will get the error:
Problems building package (Error: "package has been build before R-3.0.0")
My suggestion: Contact the authors of the package and ask them if they can either provide the source file that you can build the package by yourself or if they can bundle the Rindsel package with a newer R version.
(Or you could try to hunt down an old R version and see if you can get the thing running with an old R... However, I would not seriously suggest to do that. It would probably result in conflicting dependencies with the other required packages...)
EDIT 15-02-2018: OP asked if one can build an R package with sources that are presumeably the Rindsel source files.
Yes, basically, you could do that. You would have to make a your own description and namespace file and put the source file in the R folder than invoke the command in R to build it....
But it's not neccessary with the script files provided by the link the OP posted.
OP, just run the scripts in R! It's quite easy.
Download the zip-file and extract it on your machine.
Go to that directory. The R command would be
setwd('path/to/your/directory')
Than run the R script, e.g, the KNIndex.r. It's simple:
source('KNIndex.r')
Then the script will run and produce some output / prompts.
For future readers,
I was able to fix the error by running RStudio with administrative privileges to get the command to work.
If that does not fix it, you might wish to try
Installing "r tools" if that is not installed already. That can be downloaded from
https://cran.r-project.org/bin/windows/Rtools/
Download a relevant package that you are trying to install (e.g., tidyverse_1.3.0.zip) from https://cran.rstudio.com/
and install that from local path
It can also be installed directly from the web using install.packages("https://cran.rstudio.com/bin/windows/contrib/4.0/tidyverse_1.3.0.zip")
I had the same problem. R was not able to extract and compile the package files to the default installation directory for some system-specific reasons (not R related).
I was able to fix this by specifying the installation directory of the package lib using:
install.packages("your package", lib = 'path/to your/required/installation/directory')
You can then load the package by specifying the lib.loc option while loading it:
library('your package', lib.loc='path/to your/required/installation/directory')
A better solution:
Create a new environment variable (if you are using windows) R_LIBS_USER with the following directory path/to your/required/installation/directory.
This will change the default installation directory of the packages and make it easier to load and install them without specifying the location everytime.

Having issues installing an R package from Github

Please be patient with me as I'm a total noob, but I'm really trying to learn.
I'm trying to make a choropleth map for my country, and found an R package on Github that handles it excellently. However, I'm working on a university computer and I don't have write privileges on any drive but M://, so whenever the package tries to install on C:// it obviously throws an error. This hasn't been a problem since I can just specify a libpath as an argument on install.packages, but devtools::install_github does not seem to have such an argument.
I tried using
with_libpaths(new = "M:\R\win-library\3.2", install_github('diegovalle/mxmaps'))
But I got an error message saying
with_libpaths' is deprecated. Use 'withr::with_libpaths' instead.
I take this to mean that I need to install the "withr" package in order to use that? However, I keep getting errors when trying to install that package. First, I got
Warning in install.packages : installation of package ‘withr’ had
non-zero exit status
because of the not having access to C:// issue. I usually bypass this by installing directly from the binaries, but when I try that it tells me
"Warning in install.packages : package ‘withr’ is not available (for R
version 3.2.2)".
Other than updating my version of R (which will be a nighmare since I don't have installation privileges on this machine), how else can I either install withr or find another way to specify the directory to install the package from github?
I would suggest you to go with latest version of 3.4.All above mentioned packages are available under latest version.
Two ways to set local library paths (at least on Linux running R 3.5.3):
(1) At the beginning of your script, set the the .libPaths option to your local library path, i.e.: .libPaths("M:\R\win-library\3.2")
(2) Add to your .Renviron file a line that specifies your local library path: i.e.: R_LIBS="M:\R\win-library\3.2"
Note: For (1) You will need to manually run every time you start a new R session, whereas (2) will be set automatically when R starts.

Install r libraries

I have installed an R project on a network. It automatically installs the library in the C:\Users\\AppData\Local\Temp\downloaded_packages, however, I would like to install the library to lets say Q:\Apps\R-Project\Libraries.
I managed to install the library to the Q network using the following command:
install.packages("dplyr", lib="Q:\Apps\R-Project\Libraries", dependencies=T)
When I load the library it says that it cannot find the Rccp.
Any help how to solve that issue?
You told R to install the package in a certain location, namely Q:\Apps\R-Project\Libraries.
When you tell R to use a certain package, R will not search your entire computer whether that package exists. Usually, the packages are being saved in a standard location that R knows and where R will also search for it, once you tell it to use that package. You can view these locations with .libPaths().
If Q:\Apps\R-Project\Libraries is not a location that you have saved in .libPaths(), you have two options:
# 1) Add it to `.libPaths()` like this:
.libPaths( c( .libPaths(), "Q:\Apps\R-Project\Libraries") )
# 2) Tell `R` explicitly where to look while loading the package:
library(packagename, lib.loc = "Q:\Apps\R-Project\Libraries")
I recommend using option 1

Error in loadNamespace(name) : there is no package called 'Rcpp'

I am trying to embed RInside to my application on win7 64-bit system but when I initialize an RInside:
Rin = new RInside(argc, argv);
the following message appears:
Error in loadNamespace(name) : there is no package called 'Rcpp'
This error only occurs with Windows.
I think you get that issue when your .libPaths() differ--in other words run the .libPaths() function to see the paths stored by R for its use. Then check where RInside is installed, and make sure Rcpp is installed there too. It is a setup issue.
In other words, it should work if you have Rcpp and RInside installed where the basic R libraries are. Otherwise you have to tell the (embedded) R session about the other location (and before it starts).
There are more Windows users on the list, so you could try asking on rcpp-devel.
First get your default library locations by command ".Library" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step1.
Now you are ready to install packages which have dependencies on Rcpp.
Dirk is right in this case, BUT if the .libPaths() does not work, then please also check if you have the latest packages.
I am posting this as an ancillary answer backup which I ran into with the shiny package backend switch of their code needing Rcpp!
In this case of getting the "no package" error message, I fixed it by:
Selecting devtools package and then using this line below. (if you don't have devtools then get it with install.packages("devtools")
devtools::install_github("rstudio/shiny")
The development version of the package handled this better, and added the package as a dependency.
Mods - I realize this is an answer to an old question, but I might help others not wasting an hour like I just did.
You might find it easy if the answers are for both R studio users and non R studio users.
R Studio users
First get your default library locations by command ".Library" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step 1, you will find another folder named library, paste the unzip folder in it.
Non R studio Users
First get your default library locations by command ".libPath" in R.
Get Rcpp package from https://cran.r-project.org/web/packages/Rcpp/index.html.
Unzip and copy folder "Rcpp" to your default library locations obtained from step 1, you will find another folder named library, paste the unzip folder in it.
I was also getting this error while trying to run the 'ggplot' function from the ggplot2 package. After trying the suggestions posted here and elsewhere (checking file paths, restarting R, clearing out my environment, etc.) and encountering several other cryptic error messages, it turned out that I needed to download the latest version of base R for Windows (v3.4.1) and update my version of R-Studio to the latest version also (v1.0.153).
After doing this my 'ggplot' function was working again and I was able to render my figure from R Studio without any further issues.
I was also getting this message when trying to use ggplot. I first updating both my R for Windows to 3.4.3. Then updating R studio to version 1.1.423; then, updating all of the packages and being sure to access the R version 3.4.3 from R studio, I still got the message. None of these things fixed the error. I was ready to give up until I noticed that I was calling library(ggplot) and had ggplot::ggplot in my code. THIS WAS THE PROBLEM. I changed it to library(ggplot2) and the instance to ggplot2::ggplot(...). THIS FIXEd the problems.
I was facing a similar issue, and I simply installed the said package. It's working perfectly for me.

Resources