# R package compile errors when extending image

**URL:** <https://discourse.jupyter.org/t/r-package-compile-errors-when-extending-image/28413>\
**Category:** JupyterHub\
**Created:** [September 16, 2024, 3:16pm UTC](https://discourse.jupyter.org/t/r-package-compile-errors-when-extending-image/28413 "2024-09-16T15:16:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BenGig](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bengig/32/3200_2.png) [@BenGig](https://discourse.jupyter.org/u/BenGig)\
**Post date:** [September 16, 2024, 3:16pm UTC](https://discourse.jupyter.org/t/r-package-compile-errors-when-extending-image/28413/1 "2024-09-16T15:16:48Z")

</div>

Hi

I have extended the Jupyter notebook images for some year. But now installing from R packages fails (image [Quay](http://quay.io/jupyter/r-notebook:hub-5.1.0)).

Usually it worked like this in a Dockerfile

`RUN Rscript -e "install.packages('units')`

I’m not an R expert, but it did the job. But now I get an error during the run of `configure`:

```auto
checking for udunits2.h... no
checking for udunits2/udunits2.h... no
configure: error: 
--------------------------------------------------------------------------------
  Configuration failed because libudunits2.so was not found. Try installing:
    * deb: libudunits2-dev (Debian, Ubuntu, ...)
    * rpm: udunits2-devel (Fedora, EPEL, ...)

```

The `libudunits2-dev` package is installed, `/usr/include/udunits2.h` exists.

Looking at

`using C compiler: ‘x86_64-conda-linux-gnu-cc (conda-forge gcc 14.1.0-1) 14.1.0’`

is it possible that this compiler does not looks at the system path for include files?

It’s not limited to the units package, others fail too:

```auto
In file included from ncdf.c:2:
/usr/include/stdio.h:28:10: fatal error: bits/libc-header-start.h: No such file or directory
   28 | #include <bits/libc-header-start.h>

```

And when I’m in a notebook session, the build works without problem in R on the console or in a notebook.

---

<div class="post-metadata">

**Author:** ![minrk](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/minrk/32/13_2.png) [@minrk](https://discourse.jupyter.org/u/minrk)\
**Post date:** [September 17, 2024, 7:40am UTC](https://discourse.jupyter.org/t/r-package-compile-errors-when-extending-image/28413/2 "2024-09-17T07:40:45Z")

</div>

Since you’re using the conda compilers, this may relate to the default $CFLAGS and similar set during environment activation. In a notebook session, the environment is properly ‘activated’, while `RUN` does not activate the environment.

Can you share the full Dockerfile you are using and the image you are using where the runtime installation does work?

---

<div class="post-metadata">

**Author:** ![BenGig](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bengig/32/3200_2.png) [@BenGig](https://discourse.jupyter.org/u/BenGig)\
**Post date:** [September 17, 2024, 8:35am UTC](https://discourse.jupyter.org/t/r-package-compile-errors-when-extending-image/28413/3 "2024-09-17T08:35:38Z")

</div>

Thanks for your reply, here is a reduced version throwing the `udunits2` error described above:

```auto
FROM quay.io/jupyter/r-notebook:hub-5.1.0

USER root
RUN apt-get update && apt-get install -y \
  cmake \
  python3-pip \
  libarmadillo-dev \
  libudunits2-dev \
  libmagick++-dev \
  libglpk-dev \
  libssl-dev \
  libgdal-dev \
  libgeos-dev \
  libproj-dev \
  zip less vim man gpg povray xvfb && \
  apt-get clean

RUN Rscript -e "install.packages(pkgs=c( \
   'terra', \
   'tidyverse' ), repos=c('http://cran.r-project.org'), dependencies=TRUE, timeout=300)"

```

---

<div class="post-metadata">

**Author:** ![BenGig](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bengig/32/3200_2.png) [@BenGig](https://discourse.jupyter.org/u/BenGig)\
**Post date:** [September 18, 2024, 9:06am UTC](https://discourse.jupyter.org/t/r-package-compile-errors-when-extending-image/28413/4 "2024-09-18T09:06:20Z")

</div>

After more tests I am sure the compiler suite from Conda used in the base image is broken. I tried to set CFLAGS and to call install.packages with `configure.args=` to add the standard header and linker paths, to no success.

The search how to change the behaviour of R package builds led me to this post: [udunits2 package installation in Docker image - Super User](https://superuser.com/questions/1450441/udunits2-package-installation-in-docker-image)

Now with this before the installation statement

`RUN sed -i 's/x86_64-conda-linux-gnu-cc/gcc/g' /opt/conda/lib/R/etc/Makeconf && sed -i 's/x86_64-conda-linux-gnu-c++/c++/g' /opt/conda/lib/R/etc/Makeconf`

it works 🥳

---

<div class="post-metadata">

**Author:** ![manics](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/manics/32/85_2.png) [@manics](https://discourse.jupyter.org/u/manics)\
**Post date:** [September 18, 2024, 12:24pm UTC](https://discourse.jupyter.org/t/r-package-compile-errors-when-extending-image/28413/5 "2024-09-18T12:24:33Z")

</div>

You haven’t activated your Conda environment, so Rscript and your compilation tools may be running in an inconsistent environment.

---

<div class="post-metadata">

**Author:** ![bollwyvl](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bollwyvl/32/904_2.png) [@bollwyvl](https://discourse.jupyter.org/u/bollwyvl)\
**Post date:** [September 18, 2024, 1:25pm UTC](https://discourse.jupyter.org/t/r-package-compile-errors-when-extending-image/28413/6 "2024-09-18T13:25:39Z")

</div>

Right. If using use the stock images, using e.g. `mamba install r-terra r-tidyverse` will give consistent results, with all internally-consistent, tested binary compatibility.

Once off the happy path of what can be easily installed from `conda-forge`, an image may be better off building another, `r`-centric environment from scratch the `apt` way, and manually installing it as a kernel.
