Search code examples
ranacondayamlcondacran

How to export CRAN packages to Conda yaml file?


I need to export a Conda R environment with a number of packages. All except one are available through a Conda channel, so can be trivially added. The problem is the package BiDAG, which is on CRAN, but none of the Conda channels.

When I run install.packages("BiDAG") from inside the environment I want to export, the package is installed into the correct directory. However, conda env export > env.yml does not recognise it, as it only tracks packages that are installed by conda itself.

I've tried building from CRAN with

conda skeleton CRAN bidag
conda build r-bidag

But this crashes on two packages (r-graph and r-rgraphviz) that are available from Bioconductor, and even through conda channels, but no longer on CRAN. They are therefore not recognised and the build fails.

Is there a way to export a conda environment with this CRAN package BiDAG in the .yml?


Solution

  • Avoid install.packages in Conda Environments

    Generally, using install.packages in a Conda-managed R environment complicates the environment and I recommend against it. As you have found, Conda cannot recognize these packages, and so one loses the reproducibility that Conda offers via environment exporting. Furthermore, install.packages often has trouble locating the shared libraries and build stack that was used for all the Conda package builds. This can lead to some packages having compilation, linking, or other shared library issues.

    Building r-bidag

    The Bioconductor packages are all hosted on the bioconda channel and are prefixed with bioconductor- instead of r-. Hence, one should be able to build the package by modifying the meta.yaml that comes out of conda skeleton to replace r-graph and r-graphviz with bioconductor-graph and bioconductor-graphviz. Then build the package with

    conda build --override-channels -c conda-forge -c bioconda -c defaults r-bidag
    

    You may also need the --R argument to specify the R version for which to build.