3

I installed broom.mixed package via conda conda install -c conda-forge r-broom.mixed, however, it doesn't import and shows error message:

library(broom.mixed)

Error: package or namespace load failed for ‘broom.mixed’:
 .onLoad failed in loadNamespace() for 'TMB', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/local/home/hsinhung/anaconda3/envs/r-env/lib/R/library/TMB/libs/TMB.so':
  libopenblas.so.0: cannot open shared object file: No such file or directory

2022/1/17 added "hopefully" reproducible examples:

I created a clean R environment in Anaconda via below commands:

conda create -n r_env_test r-essentials r-base (following Anaconda R env instruction)

conda activate r_env_test

conda install -c conda-forge r-broom.mixed (following Anaconda broom.mixed instruction)

then I enter R console, and execute library(broom.mixed). The error pops up right away:

> library(broom.mixed)
Error: package or namespace load failed for ‘broom.mixed’:
 .onLoad failed in loadNamespace() for 'TMB', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/local/home/hsinhung/anaconda3/envs/r_env_test/lib/R/library/TMB/libs/TMB.so':
  libopenblas.so.0: cannot open shared object file: No such file or directory
In addition: Warning message:
package ‘broom.mixed’ was built under R version 3.6.3

As @merv suggested, here the output of package versions in the new test environment:

x86_64-conda_cos6-linux-gnu % conda list '(libblas|liblapack|r-base|r-tmb|r-broom.mixed)'
# packages in environment at /home/hsinhung/anaconda3/envs/r_env_test:
#
# Name                    Version                   Build  Channel
r-base                    3.6.1                haffb61f_2
r-base64enc               0.1_3             r36h96ca727_4
r-broom.mixed             0.2.6             r36h6115d3f_0    conda-forge
r-tmb                     1.7.16            r36h0357c0b_0    conda-forge
(r_env_test)
(22-01-17 8:16:12) <0> [~]
x86_64-conda_cos6-linux-gnu %

Any suggestion how I can get this package going in Anaconda?

Ramon
  • 63
  • 7
  • Maybe `install.packages("TMB")`? – Mikael Jagan Jan 16 '22 at 07:43
  • tmb package was installed as part of broom.mixed via ```conda install -c conda-forge r-broom.mixed```. I did try to install tmb package again but it wouldn't proceed saying "All requested packages already installed." – Ramon Jan 16 '22 at 14:46
  • The missing file appears to be the libopenblas, which I don’t think a Conda Forge build of TMB.so should be directly linking. Could be a number of issues. I’d try creating a new environment with the `r-broom.mixed` package and see if it has the same issue. What platform is this on? linux-64? – merv Jan 16 '22 at 16:32
  • Please add to the question some version details for packages in the kernel environment (e.g., `conda list '(libblas|liblapack|r-base|r-tmb|r-broom.mixed)'`). – merv Jan 16 '22 at 19:33
  • 1
    @merv: thanks for the response. I've added in the question about how I can reproduce the error in a new conda environment, as well as the package versions in the environment as you suggested. Thanks for taking a look. – Ramon Jan 17 '22 at 08:21
  • Thanks for updating - I think it makes the issue clearer. I updated my answer accordingly. I don't recommend using that old Anaconda documentation. R users should stick to Conda Forge, and include all the packages you want at creation time rather than doing a series of `conda create` then `conda install` commands. – merv Jan 17 '22 at 14:20

1 Answers1

3

Improper Channel Mixing

I believe the issue being encountered is primarily driven by mixing the defaults channel (specifically the r channel) and the conda-forge channel. This is known to lead to missing libraries and missing symbol references in shared libraries because Anaconda and Conda Forge use different build stacks and sometimes different recipes.

In this case, r-broom.mixed depends on r-tmb, which on Conda Forge depends on libblas and liblapack, but on the r channel does not have these dependencies.

Recommendation: Conda Forge only

Generally, I recommend that Conda users who want R environments should only use Conda Forge and avoid using the r channel. This is because the r channel has mostly been abandoned from what I can tell (e.g., no R version 4 releases, and most packages have not been updated for over a year).

Furthermore, I would discourage the use of the r-essentials package. Analogous to the Anaconda distribution of Python (anaconda package), the r-essentials package bundles together many packages that are anticipated to be used by data scientists, but some of it simply seems bloated to me. Something specific that troubles me about it is that it ends up pulling in Python in addition to R. No one should need to have Python mixed in with an R environment. This is due to including notebook, which if users really want to load an R environment as a kernel, they only need r-irkernel (as demonstrated below).

In summary, one should be fine simply doing:

conda create -n foo -c conda-forge r-base r-broom.mixed

Demonstration

To verify that the BLAS implementation doesn't make a difference, I tested using MKL and OpenBLAS.

I encounter no issues with the following setup:

## dedicated jupyter environment
mamba create -n jupyter jupyter nb_conda_kernels

## broom.mixed with MKL backend
mamba create -n broom_mkl r-base=4.1 r-broom.mixed r-irkernel 'blas=*=*mkl*'

## broom.mixed with OpenBLAS backend
mamba create -n broom_openblas r-base=4.1 r-broom.mixed r-irkernel 'blas=*=*openblas*'

## launch jupyter
conda activate jupyter
jupyter notebook

With Jupyter launched I can create a new notebook with either the broom_mkl or broom_openblas kernels, and running library(broom.mixed) loads without any error.

This is on osx-64 platform.

merv
  • 67,214
  • 13
  • 180
  • 245
  • 1
    Yes, it is indeed caused by mixing the defaults channel and the conda-forge channel @merv indicated. I confirmed that the problem is solved when I use only Conda Forge packages: ```conda create -n r_env_test_2 -c conda-forge r-base r-broom.mixed r-irkernel```. It is very frustrated that a normal user like me who followed the official guide but had to spend days to get supports from experts to set up a normal package. Guess it is what it is given the variety of tools and platforms available. Thanks so much for the instruction. Will use only Conda Forge whenever possible. – Ramon Jan 18 '22 at 07:12