3

I am using my school's server, so I don't have admin power to install it through sudo-apt like here. So, I create a virtual environment Renv and used conda to install it as conda install -c conda-forge jags. When in the same environment I try to install.packages("rjags") from R it gives me this error:

configure: error: "cannot link to JAGS library in /storage/hpc/data/iid49/miniconda/envs/Renv/lib64." ERROR: configuration failed for package ‘rjags’

What am I doing wrong?

UPD: Although I used conda install -c conda-forge jags command that should fit linux-64, there is no lib64 directory in /storage/hpc/data/iid49/miniconda/envs/Renv/ and JAGS is in /storage/hpc/data/iid49/miniconda/envs/Renv/lib directory

jay.sf
  • 60,139
  • 8
  • 53
  • 110
Yulia Kentieva
  • 641
  • 4
  • 13

2 Answers2

1

If you are on Debian or Ubuntu (and can install packages) you can do sudo apt install jags r-cran-rjags to install the jags binary as well as the R package interfacing. I maintain both for Debian (and so they get into Ubuntu) and the idea really is to give people binaries if installation steps may be challenging.

If you cannot access system level commands, or are on a different Linux variant, then I am afraid you need to learn enough Unix/Linux to learn to

  • configure a binary, here jags to build and install to, say, ~/lib
  • (with the binary maybe in ~/bin)
  • use this when you install the R package so that it uses libjags.so from ~/lib

or else talk to your instructor or colleagues or sysadmin and ask for help. Sadly, jags and the R package for it are not the most trivial installation out there. Which is why 'let me just pray and hope Conda will work' also failed. It's a tricky problem.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Is there a reason to avoid Conda? It provides everything needed to run on most distributions, all deliverables are precompiled, and it doesn't need `sudo`. Main issue I see with OP is not fully embracing Conda to provide all the software. – merv Aug 27 '23 at 01:39
  • Not per se, but "in practice" none of CRAN uses Conda, and Conda does not cover all of CRAN, and mixing and matching does not work. So yes, _for particular cases_ Conda may help -- and that is great and nobody has anything against it -- but that is neither generalisable to all of CRAN, nor endorsed by CRAN. So no, not a solution for the general case. – Dirk Eddelbuettel Aug 27 '23 at 02:59
0

R with Conda Forge

Conda is designed to work standalone. Letting it provide everything (including R and rjags) works fine. That is, try:

## create R 4.3 environment with rjags installed
mamba create -n r43_jags -c conda-forge r-base=4.3 r-rjags

and use the R in that environment. Note that jags need not be specified, only the r-rjags. In fact, it's best to let Conda/Mamba figure out the dependencies, rather than overspecifying things. The fact that Conda Forge has a r-rjags package means it knows how to correctly configure jags.

Generally, if using Conda for R, avoid using install.packages() and stick to the Conda Forge channel. There are some additional tips for Conda + R here:


Example in Docker

Note: Docker is only used here to demonstrate a minimal environment. I am not suggesting to use Docker, but rather just demonstrate how simple it is to get rjags running, and how this requires absolutely no sudo or compilation.

$ docker run --rm -it condaforge/mambaforge:latest
## docker shell
(base) $ mamba create -yn foo r-base=4.3 r-rjags
(base) $ conda activate foo
(foo) $ R

R version 4.3.1 (2023-06-16) -- "Beagle Scouts"
Copyright (C) 2023 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(rjags)
Loading required package: coda
Linked to JAGS 4.3.0
Loaded modules: basemod,bugs
>
merv
  • 67,214
  • 13
  • 180
  • 245
  • Sure but you can also fire up a Debian or Ubuntu container and `sudo apt install r-cran-rjags` and have the same. As I wrote above. – Dirk Eddelbuettel Aug 27 '23 at 03:00
  • @DirkEddelbuettel that's only a courtesy example to show the output - I'm not suggesting to use Docker. These commands works similarly in a HPC setting with no `sudo` access, such as OP reports. – merv Aug 27 '23 at 03:04
  • @DirkEddelbuettel I edited the answer to clarify that the use of Docker is only for demonstration purposes. – merv Aug 28 '23 at 20:27