How can I create afresh conda environment with R support and RStudio?
The code below fails to work for me:
conda create -n datascience-r rstudio
Collecting package metadata (current_repodata.json): done
Solving environment: failed with current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed
UnsatisfiableError: The following specifications were found to be incompatible with each other:
Package r-stringr conflicts for:
rstudio -> r-stringr[version='>=0.6']
Package qt conflicts for:
rstudio -> qt=5.6
Package r-httpuv conflicts for:
rstudio -> r-httpuv[version='>=1.3.3']
Package r-readxl conflicts for:
rstudio -> r-readxl[version='>=0.1.0']
Related
Trying to install r studio on anaconda but keep having problems. I tried from prompt:
conda install -c r rstudio
but got the error below:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: -
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
Examining rstudio: 75%|████████████████████████████████████████████████▊ | 3/4 [00:01<00:00, 2.51it/s]|failed
UnsatisfiableError: The following specifications were found to be incompatible with each other:
Output in format: Requested package -> Available versions
Package vs2015_runtime conflicts for:
python=3.9 -> libzlib[version='>=1.2.11,<1.3.0a0'] -> vs2015_runtime[version='>=14.15.26706|>=14.27.29016|>=14.28.29325|>=14.29.30139|>=14.32.31332|>=14.29.30037']
python=3.9 -> vs2015_runtime[version='>=14.16.27012,<15.0a0|>=14.16.27012|>=14.16.27033']
Package openssl conflicts for:
python=3.9 -> openssl[version='>=1.1.1h,<1.1.2a|>=1.1.1i,<1.1.2a|>=1.1.1j,<1.1.2a|>=1.1.1k,<1.1.2a|>=1.1.1l,<1.1.2a|>=1.1.1n,<1.1.2a|>=1.1.1o,<1.1.2a|>=3.0.3,<4.0a0|>=3.0.2,<4.0a0|>=3.0.0,<4.0a0|>=1.1.1q,<1.1.2a']
python=3.9 -> pypy3.9=7.3.9 -> openssl[version='>=3.0.5,<4.0a0']
Package libzlib conflicts for:
python=3.9 -> libzlib[version='>=1.2.11,<1.3.0a0']
python=3.9 -> pypy3.9=7.3.9 -> libzlib[version='>=1.2.12,<1.3.0a0|>=1.2.13,<1.3.0a0']
Package zlib conflicts for:
python=3.9 -> pypy3.9=7.3.9 -> zlib[version='>=1.2.11,<1.3.0a0|>=1.2.12,<1.3.0a0']
rstudio -> freetype[version='>=2.9.1'] -> zlib[version='>=1.2.11,<1.3.0a0|>=1.2.13,<1.3.0a0']
rstudio -> zlib[version='>=1.2']
Package vc conflicts for:
python=3.9 -> bzip2[version='>=1.0.8,<2.0a0'] -> vc[version='9.*|>=14,<15.0a0|>=14.2,<15']
python=3.9 -> vc[version='>=14.1,<15|>=14.1,<15.0a0']
Package sqlite conflicts for:
python=3.9 -> pypy3.9=7.3.9 -> sqlite[version='>=3.39.1,<4.0a0']
python=3.9 -> sqlite[version='>=3.33.0,<4.0a0|>=3.34.0,<4.0a0|>=3.35.5,<4.0a0|>=3.36.0,<4.0a0|>=3.37.0,<4.0a0|>=3.37.1,<4.0a0|>=3.38.5,<4.0a0|>=3.39.3,<4.0a0|>=3.39.2,<4.0a0|>=3.38.2,<4.0a0|>=3.38.0,<4.0a0|>=3.35.4,<4.0a0']
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?
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.
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
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.
I am developing a package which depends on a different package of mine which is still on github. I am using travis-ci to test the package. I added the following to the .travis.yml file to install the dmdScheme package from the dev branch:
language: r
r_github_packages: r-lib/remotes#340
r_github_packages: rkrug/dmdScheme#dev
but I get the following error at travis
Installing R packages from GitHub: rkrug/dmdScheme#dev
0.19s$ Rscript -e 'remotes::install_github(c("rkrug/dmdScheme#dev"))'
Error in parse_repo_spec(repo) :
Invalid git repo specification: 'rkrug/dmdScheme#dev'
Calls: <Anonymous> -> lapply -> FUN -> parse_git_repo -> parse_repo_spec
Execution halted
The command "Rscript -e 'remotes::install_github(c("rkrug/dmdScheme#dev"))'" failed and exited with 1 during .
The remotes package is installed.
My question:
What is the correct syntax, to specify the branch (or ref in general) to be used in the command r_github_packages?
As we can see at the Devtools dependencies vignette, we can use # to specify specific commits, etc. So, you need:
r_github_packages: rkrug/dmdScheme#dev
Coming from a python playground and being a big fan of virtualenv and ofcourse, a rookie in R, I intended to have a similar setup in my R projects and packages with the aid of packrat. (At least it seemed intuitive.)
So far, without packrat, I would run "Clean and Rebuild" on my package in RStudio and things worked as expected.
But now I have packrat installed and initialized on the project, which in turn, routes all the subsequent installs to the lib folder in the /packrat dir. This again is working as expected.
Now the issue is with rebuilding my package (which is btw, installed into the packrat by means of packrat::install() )
Every time I run "Clean and Rebuild" I get the following error in the Build window of RStudio:
==> roxygen2::roxygenize('.', roclets = c('rd', 'collate', 'namespace'))
Error in loadNamespace(name) : there is no package called ‘roxygen2’
Calls: suppressPackageStartupMessages ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
Execution halted
Exited with status 1.
In reality, I have devtools, roxygen2 and other packages (including my own) installed with packrat.
What Am I missing?