[R-pkg-devel] Installing conda dependecy onAttach

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Fri Jun 14 11:55:09 CEST 2019

On 14/06/2019 5:04 a.m., Michael Gruenstaeudl wrote:
> Assume an R package (`myRpackage`) that has a conda package
> (`condaDependecy`) as a system requirement. The file `DESCRIPTION` of
> the R package would read like:
>       Package: myRpackage
>       ...
>       SystemRequirements: condaDependecy (>= 0.1)
>       ...
> How can I ensure the automatic installation of this condaDependecy (i.e.
> `conda install condaDependency`) upon installing the R package itself
> (i.e. `install.packages("myRpackage")`), assuming that myRpackage is
> listed on CRAN?

You can't do that in a CRAN package.  You're not allowed to modify the 
user's system.

What you can do is include a function to install the dependency, and in 
your .onLoad (not .onAttach, which should rarely be used) try to detect 
if it is present.  If it is not, you can print a message telling the 
user what to do, and fail the load with a call to stop().

Duncan Murdoch

> I would prefer a method less "clunky" as
>       .onAttach = function(libname = find.package("myRpackage"), pkgname
> = "myRpackage") {
>           system("conda install -y condaDependency")
>       }
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

More information about the R-package-devel mailing list