Indirectly import R libraries from Github to R - 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?

Related

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...

Installing the dependencies of a binary package automatically

In R, I have developed my own package for work (let's call it 'foo') and I have built the package and produced a binary foo.zip with the dependencies (e.g. ggplot2) listed in the description file.
When I use the R package installer in the packages tab it doesn't automatically download the dependencies from CRAN. Ultimately I don't want the end user to have to do this and I don't intend to load it to CRAN for the time being.
I have a way with: devtools::install_dep but I don't want the user to have to do this!
Use the remotes package:
remotes::install_deps("~/RStudio/foo/foo.tar.gz")
You don't say how you're expecting users to install the package. I believe if you put it on the web on a CRAN-like repository, and tell your users to install from there, R will by default install dependencies. This involves telling them how to add your repository to the repository list, so it might be just as easy to ask them to install devtools and use devtools::install_dep.
Another possibility is to distribute your package in a source version; then this answer: https://stackoverflow.com/a/38902163/2554330 gives ideas how to proceed. One that works for me to install something like "~/RStudio/foo/foo.tar.gz" is
install_url(paste0("file://", normalizePath("~/RStudio/foo/foo.tar.gz")))
If you are on Windows, you'll probably need a slightly different way to construct the URL.
Distributing binary packages is only convenient if all your users use the same version of R as you do; they aren't guaranteed to work if the minor version number changes.

Zipping an R package with its imports/depends

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

What is the difference between a library and a package in R?

In R what is the difference between a library and a package?
I have come across posts where people refer to packages within a library. Based on this idea I interpret it that a package lives in a library (i.e I store my packages with a designated library). However I get confused when I want to use package 'x'.
I am under the imperssion I need to call the library function to get package 'x' to be in use ?
And once I have have called upon package 'x' the functions of package 'x' then become available to me ?
In R, a package is a collection of R functions, data and compiled code. The location where the packages are stored is called the library. If there is a particular functionality that you require, you can download the package from the appropriate site and it will be stored in your library. To actually use the package use the command "library(package)" which makes that package available to you. Then just call the appropriate package functions etc.
1. Package
Package extends basic R functionality and standardizes the distribution of code. For example, a package can contain a set of functions relating to a specific topic or tasks.
Packages can be distributed as SOURCE (a directory with all package components), BINARIES (contains files in OS-specific format) or as a BUNDLE (compressed file containing package components, similar to source).
The most basic package, for example created with,
library(devtools)
create("C:/Users/Documents/R-dev/MyPackage")
contains:
R/ directory where all the R code goes to, and DESCRIPTION and NAMESPACE metadata files.
2. Library
Library is a directory where the packages are stored. You can have multiple libraries on your hard drive.
To see which libraries are available (which paths are searched for packages):
.libPaths()
And to see which packages are there:
lapply(.libPaths(), dir)
To use package ‘x’, it first has to be installed in a package library. This can be done for example, with:
install.packages(‘x’) # to install packages from CRAN
or
R CMD INSTALL Xpackagename.tar.gz #to install directly from source
Once installed it has to be loaded into memory with library(x) or require(x).

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