How to Install R Packages That Are Not Available in "R-Essentials"

How to install R packages that are not available in R-essentials?

Now I have found the documentation:

This is the documentation that explains how to generate R packages that are only available in the CRAN repository:
https://www.continuum.io/content/conda-data-science

Go to the section "Building a conda R package".

(Hint: As long as the R package is available under anaconda.org use this resource. See here: https://www.continuum.io/blog/developer/jupyter-and-conda-r)

alistaire's answer is another possibility to add R packages:

If you install packages from inside of R via the regular install.packages (from CRAN mirrors), or devtools::install_github (from GitHub), they work fine. @alistaire

How to do this:
Open your (independent) R installation, then run the following command:

install.packages("png", "/home/user/anaconda3/lib/R/library")

to add new package to the correct R library used by Jupyter, otherwise the package will be installed in /home/user/R/i686-pc-linux-gnu-library/3.2/png/libs mentioned in .libPaths() .

How to install R-packages not in the conda repositories?

In the end, I got around the rl_event_hookproblems by following the approach recommended here and symlinking anaconda's libreadline to the system one:

mv ~/anaconda3/lib/libreadline.s.6.2 ~/anaconda3/lib/libreadline.s.6.2.bak
ln -s /usr/lib/libreadline.so.6.3 ~/anaconda3/lib/libreadline.s.6.2

I am still having troubles installing some dependency heavy R-packages due to failure to load shared objects when using install.packages() from withing R. However, simpler packages work fine and I can get most of the dependency heavy packages from anacondas R-repositories.

Installing all CRAN packages that are not already installed?

Frankly, I think it's painstaking job... it would last for days, even weeks (depending on resources), but here's the code (I just enjoy doing trivial things):

# get names of installed packages
packs <- installed.packages()
exc <- names(packs[,'Package'])

# get available package names
av <- names(available.packages()[,1])

# create loooong string
ins <- av[!av %in% exc]
install.packages(ins)

I still don't get why you're doing this, but, hey... some things are just not meant to be....
What wonders me the most is the fact that you've already answered your own question! You got what you needed, and it's just up to you to put things together...
Are we missing the point? Did you have something else in mind?!?

Working with an R package under a conda environment in macOS

Works for me, with some adjustments that I regard as better practice:

  • don't use RStudio from Conda - it is an abandoned project; see alternatives
  • only use conda-forge channel - mixing channels can have dynamic library issues
  • use a YAML for more reliable specification of requirements
  • explicitly declare R version (r-base)
  • include everything in the declared Imports (except what is included as dependencies of other packages)
  • conda-forge::r-cli>=3 builds are broken, so I pin that to newest working version
  • use mamba because conda is slow

Here is a YAML for creating the environment:

causalgps-env.yaml

name: causalgps
channels:
- conda-forge
dependencies:
- r-base=4.1
- r-tidyverse
- r-devtools
- r-xgboost
- r-superlearner
- r-earth
- r-ranger
- r-gam
- r-kernsmooth
- r-gnm
- r-polycor
- r-wcorr
- r-rlang
- r-glue
- r-logger
- r-cli>=2,<3

And the steps are:

  1. Create env.

    ## install Mamba if you don't have it
    ## conda install -n base conda-forge::mamba
    mamba env create -n causalgps -f causalgps-env.yaml
  2. Run R session in env.

    conda activate causalgps
    R
  3. Install package.

    library(devtools)
    install_github('fasrc/CausalGPS')
  4. Test loading.

    library(CausalGPS) ## works

Can't install any R package with jupyter notebook

The CRAN package lifedependencies is now available through Conda Forge.1 I generally recommend that all Conda R environments should source packages from Conda, otherwise one is likely to encounter compilation (really, library linking) issues.

conda install -c conda-forge r-lifedependencies

However, note that this is only available for R 4.0 and 4.1 at this time. If an R 3.6 version truly is required, then please request it by filing an Issue on the feedstock.

For future reference, there are some details on adding CRAN packages to Conda Forge in this answer.


[1]: Note that R packages are typically prefixed with r- in the Conda ecosystem.

Is it possible to install R in miniconda?

Miniconda (the light, non-GUI version of Anaconda) gives you access to conda on the command line, and with that you can install R, along with some common packages, as follows:

conda install r r-essentials --channel conda-forge

And any further R packages you need:

conda install r-<package-name> --channel conda-forge

The "Conda" ecosystem is language-agnostic, it delivers whatever you ask for (if it exists in the repository) and installs the necessary platform binaries, but I would suggest creating a virtual environment specific to each "language platform", to ensure isolation.

Example:

conda create -n r_env r-essentials r-base

conda activate r_env

conda list

And work within this environment to run R and install new packages.

To leave the virtual environment:

conda deactivate


Related Topics



Leave a reply



Submit