1
votes

I'm running Miniconda3 on Ubuntu 20.04 LTS OS and have installed R-4.0.3 in a conda environment. When I try to install packages from CRAN repositoriesvia R prompt, I get a

x86_64-conda-linux-gnu-c++: not found

I have ran source activate qwe (qwe is the name of the environment) as advised in Anaconda documentation on built-in gcc tool chain. I also ran source activate root

I have also installed the comiler tool chain using conda install gxx_linux-64

My echo $PATH returns the following:

/home/sreedta/miniconda3/envs/qwe/bin:/home/sreedta/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Here is the full output when I tried to install a package called bayesm

install.packages("bayesm") --- Please select a CRAN mirror for use in this session --- trying URL 'https://cloud.r-project.org/src/contrib/bayesm_3.1-4.tar.gz' Content type 'application/x-gzip' length 2269364 bytes (2.2 MB) ================================================== downloaded 2.2 MB

  • installing source package ‘bayesm’ ... ** package ‘bayesm’ successfully unpacked and MD5 sums checked ** using staged installation ** libs x86_64-conda-linux-gnu-c++ -std=gnu++11 -I"/home/sreedta/miniconda3/envs/qwe/lib/R/include" -DNDEBUG -I../inst/include/ -I'/home/sreedta/miniconda3/envs/qwe/lib/R/library/Rcpp/include' -I'/home/sreedta/miniconda3/envs/qwe/lib/R/library/RcppArmadillo/include' -DNDEBUG -D_FORTIFY_SOURCE=2 -O2 -isystem /home/sreedta/miniconda3/envs/qwe/include -I/home/sreedta/miniconda3/envs/qwe/include -Wl,-rpath-link,/home/sreedta/miniconda3/envs/qwe/lib -fpic -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/sreedta/miniconda3/envs/qwe/include -fdebug-prefix-map=/home/conda/feedstock_root/build_artifacts/r-base_1603047469992/work=/usr/local/src/conda/r-base-4.0.3 -fdebug-prefix-map=/home/sreedta/miniconda3/envs/qwe=/usr/local/src/conda-prefix -c RcppExports.cpp -o RcppExports.o /bin/sh: 1: x86_64-conda-linux-gnu-c++: not found make: *** [/home/sreedta/miniconda3/envs/qwe/lib/R/etc/Makeconf:180: RcppExports.o] Error 127 ERROR: compilation failed for package ‘bayesm’
  • removing ‘/home/sreedta/miniconda3/envs/qwe/lib/R/library/bayesm’
  • restoring previous ‘/home/sreedta/miniconda3/envs/qwe/lib/R/library/bayesm’

The downloaded source packages are in ‘/tmp/Rtmp6hsphd/downloaded_packages’ Updating HTML index of packages in '.Library' Making 'packages.html' ... done Warning message: In install.packages("bayesm") : installation of package ‘bayesm’ had non-zero exit status

3

3 Answers

0
votes

If you have R in a Conda environment, I would strongly recommend avoiding installs through utils::install.packages. Instead, install through Conda. Many CRAN packages are available through the Conda Forge channel, usually with an "r-" prepended to the package name. So, try

conda install -n qwe -c conda-forge r-bayesem
1
votes

Thanks to @merv, I got to understand the different ways to build an environment using conda and succeeded in my goal. He posted a link to one of his answers about building with environment.yaml files with specific compilers and dependencies. I also learned something valuable: "better to keep the channels you source libraries from to a minimum. In the previous installations I was combining defaults, r, pypi, and conda-forge channels". In this successful set-up it is only conda-forge & pypi.

Here are the steps I followed to get the compilation working correctly for R in my miniconda3 installation.

  1. Removed my existing installation completely:
(base) $ rm -rf ~/miniconda3
  1. I also removed the following line from the /etc/profile and ~/.bashrc
export PATH="~/miniconda3/bin:$PATH"

(this was necessary since at the time of installation, I had said "yes" to conda init)

  1. Reinstalled miniconda3 (after downloading and before installation ensure you do a SHA256 test to ensure file integrity - my first download was corrupted)

  2. Created a new environment asd using the .yaml below. My objective for this exercise was to make R and Python work with each other using rpy2 and pybrms.

name: asd
channels:
  - conda-forge   # @merv had mentioned as best source for R related stuff
  - defaults      # only conda-forge has R-base=4.0.3 so defaults are second
  - dependencies: # this is where I added the gcc suite of libraries per @merv
  - python=3.6.11
  - libcurl
  - libv8
  - libgcc-ng  # gcc c
  - libgfortran-ng # gcc fortran
  - libgfortran4   # gcc fortran
  - libglib        # also needed for gcc (I could be wrong)
  - libstdcxx-ng   # gcc c++ / g++
  - conda
  - pip
  - wheel
  - r-base=4.0.3   # default channels only go as high as R-base=3.6.1.
  - pip:
      - rpy2==3.3.6
      - pybrms==0.0.33
  1. While still in (base) $ prompt I source activated the new environment with
(base) $ source activate asd # this changes the prompt to (asd) $ 
  1. Then I installed the following 3 R packages directly from conda-forge r-v8, r-rcpp, and r-rcpparmadillo
(asd) $ conda install -c conda-forge r-v8  # repeat for r-rcpp & r-rcpparmadillo
  1. At the (asd) $ prompt, I launched R with (asd) $ R to get to the R prompt and ran
install.packages("bayesm")  # this was a package from CRAN that was failing compilation as a source package

this was the test I was performing the last 3 days to test how R in a conda environment can access the built-in gcc compilers instead of the system compilers

  1. I quit R with quit() at the R prompt

quit()

  1. To get back to the (asd) $ prompt to install more R packages
(asd) $ conda install -c conda-forge boost-cpp # prerequisite for r-bh

(asd) $ conda install -c conda-forge r-bh # prerequisite for r-brms

This will install a whole bunch of R libraries.

This was equal parts frustrating and rewarding as a new user of Anaconda, R, and Python on a new OS (Linux-Ubuntu). I hope this comes in handy for another new user.

0
votes

Step1: find x86_64-conda-linux-gnu-c++ in home directory

[showteth@localhost ~] find ~ -name "x86_64-conda-linux-gnu-c++"
/home/showteth/anaconda3/envs/r351/bin/x86_64-conda-linux-gnu-c++

Step2: add /home/showteth/anaconda3/envs/r351/bin to .Renviron (in your home directory)

echo 'PATH=${PATH}:/home/showteth/anaconda3/envs/r351/bin' >> .Renviron

Step3: restart rstudio server for configuration to take effect