2

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 run 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 and installed the compiler tool chain using conda install gxx_linux-64

My $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
i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
sreedta
  • 123
  • 1
  • 9

4 Answers4

2

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.

Community
  • 1
  • 1
sreedta
  • 123
  • 1
  • 9
1

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
merv
  • 67,214
  • 13
  • 180
  • 245
  • Thanks for the recommendation. After I posted here, I began exploring R packages on Conda-forge. I have not yet started installing but your feedback is a nice confirmation to have. Since I began using Ubuntu recently, I wanted to make sure I knew the eco-system thoroughly. I would like to know for completeness how I can make compilation work in Conda. On Windows, I can use RTools for regular R and R in Anaconda. I thought it would be easier in Linux but finding it to be otherwise – sreedta Oct 21 '20 at 02:23
  • Upon additional research into the new compiler tool sets in Anaconda - see here (https://www.anaconda.com/blog/utilizing-the-new-compilers-in-anaconda-distribution-5), I saw this section where it states "New compiler packages can be conda-installed, but they’re a bit tricky to use. Specifically, because they are designed with (pseudo)cross-compiling in mind, all of the executables in a compiler package are “prefixed.” Instead of gcc, you have something like x86_64-conda_cos6-linux-gnu-gcc" – sreedta Oct 21 '20 at 13:51
  • 1
    The same page also details how to activate the commpilers: "Conda-build does this activation for you through activation hooks installed with the compiler packages in CONDA_PREFIX/etc/conda/activate.d—no additional effort is necessary. As a side note, you can activate the root environment by typing source activate root." I did as advise but without success. I'm sure others have run into this situation. I will look for a solution and get back here I find it – sreedta Oct 21 '20 at 13:53
  • Searching further I found this page and a section on "CMake and sysroots" https://conda.io/projects/conda-build/en/latest/resources/compiler-tools.html#an-aside-on-cmake-and-sysroots – sreedta Oct 21 '20 at 14:07
  • @sreedta Sorry, I didn't realize you directly needed the compilers - I thought you only needed to install R packages, which through `conda install` should handle all the compilation in the background. Anyway, I gave [an answer](https://stackoverflow.com/a/64253999/570918) recently where I described how I use the compilation tools. Not sure if that helps. – merv Oct 21 '20 at 19:57
  • thank you so much for the additional information. I need the gfortran, gcc, and gxx - I have the following question (this is my first foray with Linux/Ubuntu hence some of the questions are basic and reflect my utter ignorance.) just as you noted fortran-compiler and cxx-compiler (is cxx same as gxx or c++?) is there a gcc-compiler that I can include in the yaml file? In the yaml file can I specify the version and build of the library of interest to me? – sreedta Oct 21 '20 at 20:47
  • when I searched for a cxx-compiler on Anaconda Cloud, I got a bunch of them with nammes such as libstdcxx-ng and libcxx - Is there a description I can look for that helps me understand what they provide and how they differ? – sreedta Oct 21 '20 at 21:03
  • 1
    @sreedta btw, if you just C, C++, and Fortran compilers, then you can use the metapackage named `compilers` which will pull in all three. – merv Nov 23 '20 at 22:28
  • thanks for the tip! As I continue to help myself and others in setting up these environments, your input has been very valuable for me. – sreedta Nov 24 '20 at 16:53
1

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

showteth
  • 340
  • 3
  • 10
0

If you are failing install package using rstudio-server/rstudio IDE, try install r package in R console without IDE

 mamba activate r_test
 mamba install -c conda-forge gxx_linux-64
 R
 # install package in R native console, not in rstudio/rstudio-server
 BiocManager::install("ClassDiscovery")
keke Sun
  • 1
  • 1