Zipping an R package with its imports/depends - r

I am working on a package, and it imports the development version of the DT package from github as well as several other packages. If I want to distribute my package to a computer that does not have internet access, is there a way I can zip my package with all of its imports/depends so that I don't have to distribute separate zips for each of the packages that it imports/depends, and install each of the packages separately?
It would be nice to have a single tar.gz that contains everything. Is this possible?
Kind Regards

Well, if you use an R kernel for jupyter, and Conda installation, there is a way to create and distribute R bundle
Please read "Creating your custom R bundle", link: https://www.continuum.io/blog/developer/jupyter-and-conda-r

Related

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

Is there a way to automatically install all package requirements for an R file?

I have an R file, but it has packages which are not installed on my R installation. Is there a utility which determines these dependencies from the R file and installs all of them? I don't want to manually install them one by one.
The pacman package offers an efficient way to install / load packages in a single line.
You can refer to this article.
I'm not aware of a way that installs packages completely automatically, as there might be namespace overlap between functions, etc...

Indirectly import R libraries from Github to R

I have just built a function and planned to put it into Github. The problem is that my function uses a lot of other R packages (e.g., dplyr, tidyverse,...), leading to when people clone my package from Github to R using remotes::install_github, they will have to additionally install those packages (e.g., dplyr, tidyverse,...). I wish when they install my package, they can use my package immediately. In other words, is any way to let they be able to simultaneously install all those packages when installing my R package.
My potential solution is that I will create a separate RData file whose role is to install and call those R libraries. Does it work?

Can we install a `.zip` R package under linux?

I have found an old R package with a .zip extension on my PC.
I would like to run it, but I do not have the tar.gz that was used to
create it and I use linux. What are my options?
Few, essentially.
A .zip package for R is almost surely a binary built for Windows so you need to find a suitable Windows computer -- or emulator -- to use it.
So, this can be done this way:
install wine (wine is not an emulator),
install R for Windows, which you download manually from CRAN
install the zip package using the usual commands (install.packages("filename.zip",source=NULL)). You will probably get error messages for the dependencies, but incrementally installing those, it should work.

How to convert R package and dependencies to debian packages?

I need to install R packages in several nodes (10+) in AWS.
I wont be able to open R shell in each and do install.packages("foo")
This will be done using a configuration management tool like Puppet and it'll be easier if i can do an apt-get installation of R packages automatically.
I found a list of R debian packages here:
http://cran.cnr.berkeley.edu/bin/linux/ubuntu/lucid/
But it does not contain all the packages that i need.
Is there a way to convert any R package and it's internal dependencies to a Debian package similar to the approach used in creating r-cran-*.deb?
Have you looked at http://debian-r.debian.net/ ?
All CRAN (and many other) packages already packaged
You can install packages without starting the R console. You can download the tar.gz packages from the cran website. For example here is the tar.gz for the randomForest package: http://cran.r-project.org/src/contrib/randomForest_4.6-7.tar.gz
R CMD INSTALL ${package}.tar.gz
The cran2deb project claims to do exactly this, turning an R package into a Debian package and noting the correct dependencies.
I haven't used it myself yet.

Resources