简体   繁体   中英

Is it possible to install external dependencies for R package on download

I have an R package with certain dependencies to C libraries on github, currently without the dependency C libraries inside the repo.

Normally, I would install R packages from GitHub with the following:

install.packages("devtools")
library(devtools)
install_github("github_repo/package_name")

All of the C code used by the R package is naturally located inside the subfolder package_name/src . But I'm confused how to release the C library dependencies necessary for the R package to work.

Based on the documentation in "Writing R Extensions", https://cran.r-project.org/doc/manuals/r-release/R-exts.htmlk , these dependencies should be listed:

"Dependencies external to the R system should be listed in the 'SystemRequirements' field, possibly amplified in a separate README file."

That makes sense. And I could put in the README how to install these C library dependencies, or even put the libraries in the github repo (if they are not too large).

However, this could easily become a mess for people to download, which is why I like Docker files, ie within Dockerfile , I would add the following:

RUN apt-get update && apt-get install -y \
    make \
    clang \
    require_c_library1 \
    require_c_library2 \
    require_c_library3

Is it possible to load these C library dependencies in such a manner before the R package installs (ie R CMD INSTALL calls R CMD SHLIB which installs all C code and C dependencies in Makevars )?

Or is the only option to (1) put each and every C dependency in the R package to be downloaded and compiled at devtools::install_github("github_repo/package_name") or (2) ask users to install all of these dependencies in the README, and hope they do it correctly (and don't e-mail me endlessly)?

There could be something I'm not understanding here, so please correct me

tl;dr: I wish!

There were earlier, related questions. In essence you desire to have the (well-honed) CRAN dependencies (which work in a well-defined universe) become more universal across the host operating systems---of which there are too many, and too many variants.

Take example libries for XML, PostgreSQL, PNG or JPEG. Their names (and versions) will differ across operating systems so this, sadly, is really really hard.

[ I do have a package RcppAPT which allow you to query apt 's cache from R, but that only addresses flow 'the other way' -- and is of course only for a subset of users as it is of no use to folks on Windows, macOS, RH/CentOS and so on. ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM