4

In one of my conda environments in terminal, I am able to successfully install the package 'rjags'. However, when I run R within that environment and run library(rjags), I get the following error:

Loading required package: coda Error: package or namespace load failed for 'rjags': .onLoad failed in loadNamespace() for 'rjags', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/user-path/anaconda3/envs/r-env/lib/R/library/rjags/libs/rjags.so': /user-path/anaconda3/envs/r-env/lib/R/library/rjags/libs/rjags.so: undefined symbol: _ZN4jags7Console10setRNGnameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj In addition: Warning messages: 1: package 'rjags' was built under R version 3.6.3 2: package 'coda' was built under R version 3.6.3

If I install and with R, perform library(rjags) in another environment or in the base environment, everything works fine. I am wondering what this error message means and how to resolve it.

The output of conda list "^(libstdcxx-ng|r-base|r-coda|jags|r-rjags)$" is:

# packages in environment at /user-path/anaconda3/envs/r-env:
#
# Name                    Version                   Build  Channel
jags                      4.3.0                h26a2512_0    conda-forge
libstdcxx-ng              9.1.0                hdf63c60_0  
r-base                    3.6.1                h9bb98a2_1  
r-coda                    0.19_3            r36h6115d3f_2    conda-forge
r-rjags                   4_10              r36h0357c0b_1    conda-forge
merryberry
  • 91
  • 1
  • 9
  • Could you add some details about the env to the question? I think the output from the following would be a minimum for others to attempt to replicate the issue: `conda list "^(libcxx|r-base|r-coda|jags|r-jags)$"` – merv Jun 24 '20 at 20:32
  • 1
    @merv Sure, I put the output above – merryberry Jun 24 '20 at 22:17
  • This is linux platform? If so, mind checking this instead of my previous set: `conda list "^(libstdcxx-ng|r-base|r-coda|jags|r-rjags)$"` – merv Jun 24 '20 at 23:07
  • 1
    @merv Yes, this is linux. I have updated the above to reflect the changes. – merryberry Jun 25 '20 at 00:05
  • Thanks, this was helpful and I was able to recreate the error. – merv Jun 25 '20 at 01:02

1 Answers1

3

Channel Mixing Gone Wrong

I suspect that the error is due to mixing of Conda Forge and Anaconda packages. The organizations use different build stacks and so the dynamic libraries they build can end up having different internal definitions (for details, see this Issue on the Conda Forge repository). For example, in this case rjags.so is built to look for a symbol in the libraries that it links to, but it fails to find it in the Anaconda builds. Unfortunately, it links to too many (check with ldd rjags.so) for me to track down which specifically is causing the issue.

However, you still have a some options to get rjags working, just not a precision fix. In all cases the solution is to prioritize the conda-forge channel.

Option 1: Create a new dedicated env

If you don't actually need rjags in this specific env, then create a new one with the packages you will need. However, when doing so, make conda-forge the priority channel over defaults:

conda create -n rjags_env -c conda-forge r-rjags
conda activate rjags_env
conda config --env --add channels conda-forge

Option 2: Recreate env using Conda Forge

If your goal is to add rjags to the existing env, and you can't figure out the specific package that needs to change, you instead could recreate the env with the updated priority.

First, export the env to a YAML like

conda env export -n r-env --no-builds > rjags_env.yaml

Next, edit this file so that the channels section reads:

name: rjags_env
channels:
  - conda-forge
  - defaults
dependencies:

Finally create a new version of the env with

conda env create -f rjags_env.yaml -n rjags_env

Additional notes

I also looked into using the --update-deps flag with conda install, but that forces the env to update to R v4.0.1 and breaks the r-coda install.

merv
  • 67,214
  • 13
  • 180
  • 245
  • 2
    Thanks! After reading this, I was actually able to resolve this by updating all the packages to be on the conda-forge channel so there was consistency. Also- in the code block under Option 1, I believe 'channel' should be 'channels'. @merv – merryberry Jun 25 '20 at 16:56
  • 1
    @merryberry great - yeah I figured there was a way to do it in place, but it just was not coming to mind. Glad you got it working! – merv Jun 25 '20 at 21:13
  • This worked for me (Option 1) thank you @merv – asmith Nov 04 '21 at 03:02