Install R packages from github downloading master.zip - r

I probably have some issues in my connectivity (some sort of blocks, I don't know) and I can't install directly form gitHub
> install_github("assertthat")
Installing github repo(s) assertthat/master from hadley
Installing assertthat.zip from https://github.com/hadley/assertthat/archive/master.zip
I tried with lots of other packages, same result. However, I am able to download master.zip form the browser. Can you tell if it's possible install directly the .zip? thanks.

This answer is just a refined version of my comments. Essentially you can install packages using devtools by unzipping a local zipfile downloaded from github, and then running the install function
install("path/to/unzipped_pkg_zip_file")
The latest dev version of devtools contains an install_local utility function that makes it easy to work directly with local zip files.

Related

Download R package from github as tar.gz

I need to have the tar.gz build version of a package from git.
The git link would look like
devtools::install_github('repo/package#x.1.0')
Let's assume it is
devtools::install_github("tidyverse/lubridate") but instead of installing I need the actual file so I can install it in in an offline container at some point.
The package I need is not on CRAN, on git only, and I need a specific version of the release, not the latest.
I tried to run a different download.file arguments, no success.

Air-gapped env- Installing R package source vs binaries

We have a ubuntu linux server in our office which is a air-gapped environment. There is no internet access to external network.
However I would like to install few R packages like ggplot2, Database Connector, dplyr, Tidyverse etc. I have more than 10-15 packages to download
While I cannot write the usual command install.packages("DatabaseConnector"), I have to download the zipped folders from CRAN as shown here.
I am new to R. So, can you help me with my questions given below?
a) Why is there are no files for linux systems? I only see windows binaries and macOS binaries. Which one should I download?
b) Should I download binaries or package source? which one is easy to install?
c) When I download packages like above as zipped file from CRAN like shown here, will the dependencies be automatically downloaded as well? Or should I look at error messages and keep downloading them one by one?
d) Since I work in a Air-gapped environment, what would be the best way to do this process efficiently.
Under linux packages are always installed from source. There are no official binary packages for linux. However, your distro might offer some of them in the official repositories. Ubuntu does. However these tend to be quite old versions and usually limited to a handfull of the most important packages. So, for linux you have to download the source packages. The zip files are for windows and will not work.
You will also need to download all of the dependencies of the packages. For something like tidyverse this will be a huge number. Tracking those by hand is a lot of work. Easiest is probably to use a package like miniCRAN outside of your airgapped system to build a selective copy of CRAN. You can specify the packages you want and the package will download all dependencies. You can then copy the downloaded directories to your server, point install.packages in the right direction and install as usually using install.packages. For details see https://andrie.github.io/miniCRAN/articles/miniCRAN-introduction.html.
You might also run into the problem that your system does not have all of the depencies needed to build all of the packages. Under ubuntu you need for example to install libxml2-dev to be able to install the xml package. For that you need to use the package manager of ubuntu. How to do that on an airgapped system is another issue

How to create CRAN ready R package that has external dependency libxml2

I have created an R package that I would like to submit to CRAN. It contains code that needs to be compiled in plain C and this code depends on the libxml2 library.
My current solution is to let Linux and Mac users install the libxml2-dev package, which lets them compile and install the R source package.
For Windows, I have created a special binary R-package that contains the required binary dependency. When reading the CRAN guidelines I see that only source packages may be uploaded and that they may not contain any binary files.
After those guidelines, my questions are:
Is it ok for Mac/Linux to have the user install libxml2-dev prior to installing the R package or are there alternative solutions?
How should I do for Windows where the libxml2 is not straight forward to install for an end user?
As mentioned above, you can just copy over what the xml2 package does:
To get things to work on Linux/MacOS, copy the files configure and /src/Makevars.in. Note that macOS includes a copy of libxml2 by default, so you can safely link to -lxml2 as you would do on Linux.
For Windows need to copy the files src/Makevars.win and tools/winlibs.R from xml2. This is a simple script that automatically downloads and statically links libxml2 from rwinlib when building the R package on Windows.
These build scripts are tested to work on (almost) any platform.

Error in R: (Package which is only available in source form, and may need compilation of C/C++/Fortran)

I'm trying to install the 'yaml' and 'stringi' packages in R-Studio, and it keeps giving me these errors:
> install.packages("stringi")
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘stringi’
These will not be installed
or
> install.packages('yaml')
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘yaml’
These will not be installed
How can I get these to install properly?
The error is due to R being unable to find a binary version of the package on CRAN, instead only finding a source version of the package and your Windows installation being unable to compile it. Usually this doesn't occur, but in this case was caused by the (temporary) outage of some of the mirrors at CRAN. If you type:
> getOption('repos')
CRAN CRANextra
"http://cran.rstudio.com" "http://www.stats.ox.ac.uk/pub/RWin"
attr(,"RStudio")
[1] TRUE
You will see that R uses "http://cran.rstudio.com" by default to look for a package to download. If you see the cran mirrors web page you can see at the top that "http://cran.rstudio.com" actually redirects you to different servers world wide (I assume according to the geo location).
When I had the above issue, I solved it by manually changing the repo to one of the urls in the link provided. I suggest you use a different country (or even continent) in case you receive the above error.
I provide below some of the urls in case the link above changes:
Brazil http://nbcgib.uesc.br/mirrors/cran/
Italy http://cran.mirror.garr.it/mirrors/CRAN/
Japan http://cran.ism.ac.jp/
South Africa http://r.adu.org.za/
USA https://cran.cnr.Berkeley.edu/
You need to run the function install.packages as follows:
install.packages('<package_name>', repo='http://nbcgib.uesc.br/mirrors/cran/')
#or any other url from the list or link
One of them should then work to install a binary from an alternative mirror.
You need to install RTools to build packages like this (i.e., a source package rather than a binary). After you install Rtools, then try again to install.packages("ggplot2") and R will prompt you with:
Do you want to attempt to install these from source?
y/n:
(see the picture below)
You need to answer y and it will try to compile the package so it can be installed.
Struggled with this issue today, solved it for now by first downloading the windows binary and then installing e.g.
install.packages("https://cran.r-project.org/bin/windows/contrib/3.3/stringi_1.1.1.zip", repos =NULL)
Just go to https://cran.r-project.org/ and then R Binaries/Windows/contrib and copy the url as argument to install.packages()
Install the package from a zip file - downloadable from the r-project website.
In basic R
go to Packages
Install packages from local files.
In RStudio
go to Packages
Install packages
Install from Package Archive File.
I had this issue when using an out-of-date version of R, so no binaries were available. The simple solution was to update my version of R.
Anything worked for me, until I found out my computer had an old version of R installed. Uninstalling everything and installing the newest R version worked!
I had to download the latest version of Rtools:
Go into the downloads folder and double click it to install it.
Close and reopen any R session.
Now packages should install like normal.
However, if you still have trouble, try installing the package from source (using type="source")
Like this:
install.packages("dplyr", type="source")

How do I install RGoogleDocs from GitHub?

I see that there is a new version of RGoogleDocs in GitHub. It is Version 0.6-0.
https://github.com/duncantl/RGoogleDocs.
How do I install it in the 64 bit version of R? In the past, Duncan Temple Lang provided pointed me to a zip file that contained the Windows binary file. I downloaded it and executed this command to get it installed
install.packages("C:/Users/Farrel/Dropbox/RGoogleDocs_0.5-0.zip",repos=NULL)
If you have Rtools installed, you can use the devtools package and its install_github function to directly install packages from github.
For this particular package, you can click the button that says ZIP that is to the left of the git URL to download the zip file. Then, unzip it into your working directory. Or, you could use TortoiseGit to clone the code into a local directory.
Then, you can use install.packages with type='source'.
install.packages("duncantl-RGoogleDocs-0e3879c/", type='source', repos=NULL)
But, in general, it really would be a good idea to learn to build packages.
See the R on Windows FAQ about installing packages from source.

Resources