# How to add additional packages to R?

**URL:** <https://discourse.jupyter.org/t/how-to-add-additional-packages-to-r/16258>\
**Category:** JupyterHub\
**Tags:** help-wanted, docker\
**Created:** [October 11, 2022, 9:27am UTC](https://discourse.jupyter.org/t/how-to-add-additional-packages-to-r/16258 "2022-10-11T09:27:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmfama20](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/dmfama20/32/7792_2.png) [@Dmfama20](https://discourse.jupyter.org/u/Dmfama20)\
**Post date:** [October 11, 2022, 9:27am UTC](https://discourse.jupyter.org/t/how-to-add-additional-packages-to-r/16258/1 "2022-10-11T09:27:15Z")

</div>

Hi,

I need some additonal packages added to R, which is used in the Jupyter Notebook R Stack.  
So far I tried to modify the corresponding Dockerfile (added some packages (r-qboxplot, r-hhi,…))

```auto
ARG OWNER=jupyter
ARG BASE_CONTAINER=$OWNER/minimal-notebook
FROM $BASE_CONTAINER

LABEL maintainer="Jupyter Project <jupyter@googlegroups.com>"

# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER root

# R pre-requisites
RUN apt-get update --yes && \
    apt-get install --yes --no-install-recommends \
    fonts-dejavu \
    unixodbc \
    unixodbc-dev \
    r-cran-rodbc \
    gfortran \
    gcc && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

USER ${NB_UID}

# R packages including IRKernel which gets installed globally.
# r-e1071: dependency of the caret R package
RUN mamba install --quiet --yes \
    'r-base' \
    'r-caret' \
    'r-crayon' \
    'r-devtools' \
    'r-e1071' \
    'r-forecast' \
    'r-hexbin' \
    'r-htmltools' \
    'r-htmlwidgets' \
    'r-irkernel' \
    'r-nycflights13' \
    'r-randomforest' \
    'r-rcurl' \
    'r-rmarkdown' \
    'r-rodbc' \
    'r-rsqlite' \
    'r-shiny' \
    'r-tidyverse' \
    'r-qboxplot' \
    'r-hhi' \
    'r-ineq' \
    'r-hmisc' \
    'r-BSDA' \
    'r-moderndive' \
    'r-mosaic' \
    'r-micEconIndex' \
    'unixodbc' && \
    mamba clean --all -f -y && \
    fix-permissions "${CONDA_DIR}" && \
    fix-permissions "/home/${NB_USER}"

# `r-tidymodels` is not easy to install under arm
RUN set -x && \
    arch=$(uname -m) && \
    if ["${arch}" == "x86_64"]; then \
        mamba install --quiet --yes \
            'r-tidymodels' && \
            mamba clean --all -f -y && \
            fix-permissions "${CONDA_DIR}" && \
            fix-permissions "/home/${NB_USER}"; \
    fi;

```

Unfortunately, when I try to build this Dockerfile I get the error

```auto
#6 5.861 Encountered problems while solving:                                                                                                                                
#6 5.861 - nothing provides requested r-qboxplot
#6 5.861 - nothing provides requested r-hhi
#6 5.861 - nothing provides requested r-moderndive
#6 5.861 - nothing provides requested r-miceconindex
#6 5.861 - nothing provides r-ggrepel needed by r-mosaic-1.8.3-r40hc72bb7e_0
#6 5.861 - package r-bsda-1.2.0-r40hc72bb7e_0 requires r-base >=4.0,<4.1.0a0, but none of the providers can be installed

```

Any ideas how to add some additional packages another way?

PS: I’m running jupyterhub via docker-compose as described here

> **[GitHub - jupyterhub/jupyterhub-deploy-docker: Reference deployment of...](https://github.com/jupyterhub/jupyterhub-deploy-docker)**
>
> Reference deployment of JupyterHub with docker. Contribute to jupyterhub/jupyterhub-deploy-docker development by creating an account on GitHub.

TIA!  
Best,  
Alex

---

<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:** [October 11, 2022, 1:40pm UTC](https://discourse.jupyter.org/t/how-to-add-additional-packages-to-r/16258/2 "2022-10-11T13:40:24Z")

</div>

If you’re absolutely committed to using conda-forge (which is a fine goal, as it would benefit other users), there’s more work ahead.

> [@Dmfama20](#):
>
> `nothing provides requested r-qboxplot`

It’s like it says: those packages aren’t available from `conda-forge`, and it all starts with [`staged-recipes`](https://github.com/conda-forge/staged-recipes).

You can either:

- [request a new package](https://github.com/conda-forge/staged-recipes/issues/new/choose)
  - hope for the best

- contribute (and maintain) them yourself
  - have a look at the [knowledge base](https://conda-forge.org/docs/user/introduction.html#can-i-contribute-packages-to-conda-forge)
  - instead of writing by hand, start with with [`conda_r_skeleton_helper`](https://github.com/bgruening/conda_r_skeleton_helper)
  - submit them to `staged-recipes`

> [@Dmfama20](#):
>
> ```auto
> # R pre-requisites
> RUN apt-get update --yes && \
> apt-get install --yes --no-install-recommends r-cran-rodbc \
> 
> ```

Even as this “works,” the `r` installed by `conda` won’t be able to find it.

You may want to everything with the system `r`, a la: [`install.R`](https://repo2docker.readthedocs.io/en/latest/config_files.html#install-r-install-an-r-rstudio-environment) and using that package manager directly.

---

<div class="post-metadata">

**Author:** ![Dmfama20](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/dmfama20/32/7792_2.png) [@Dmfama20](https://discourse.jupyter.org/u/Dmfama20)\
**Post date:** [October 13, 2022, 7:06am UTC](https://discourse.jupyter.org/t/how-to-add-additional-packages-to-r/16258/3 "2022-10-13T07:06:28Z")

</div>

Hi,  
thank you very much for your answer. Finally, I managed it by creating a new “private\_Dockerfile” which is used for a singleuser:

```auto
ARG OWNER=jupyter
ARG BASE_CONTAINER=$OWNER/minimal-notebook
FROM $BASE_CONTAINER

# Fix: https://github.com/hadolint/hadolint/wiki/DL4006
# Fix: https://github.com/koalaman/shellcheck/wiki/SC3014
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

USER root

# R pre-requisites
RUN apt-get update --yes && \
    apt-get install --yes --no-install-recommends \
    fonts-dejavu \
    unixodbc \
    unixodbc-dev \
    r-cran-rodbc \
    gfortran \
    gcc && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

USER ${NB_UID}

# R packages including IRKernel which gets installed globally.
# r-e1071: dependency of the caret R package
RUN mamba install --quiet --yes \
    'r-base' \
    'r-caret' \
    'r-crayon' \
    'r-devtools' \
    'r-e1071' \
    'r-forecast' \
    'r-hexbin' \
    'r-htmltools' \
    'r-htmlwidgets' \
    'r-irkernel' \
    'r-nycflights13' \
    'r-randomforest' \
    'r-rcurl' \
    'r-rmarkdown' \
    'r-rodbc' \
    'r-rsqlite' \
    'r-shiny' \
    'r-tidyverse' && \
    mamba clean --all -f -y && \
    fix-permissions "${CONDA_DIR}" && \
    fix-permissions "/home/${NB_USER}"

# `r-tidymodels` is not easy to install under arm
RUN set -x && \
    arch=$(uname -m) && \
    if ["${arch}" == "x86_64"]; then \
        mamba install --quiet --yes \
            'r-tidymodels' && \
            mamba clean --all -f -y && \
            fix-permissions "${CONDA_DIR}" && \
            fix-permissions "/home/${NB_USER}"; \
    fi;

RUN R -e "install.packages('qboxplot',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('hhi',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('ineq',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('hmisc',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('BSDA',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('moderndive',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('mosaic',dependencies=TRUE, repos='http://cran.rstudio.com/')"
RUN R -e "install.packages('micEconIndex',dependencies=TRUE, repos='http://cran.rstudio.com/')"

```

…and building it …

```auto
docker build -f private_Dockerfile -t jupyterhub-user --build-arg JUPYTERHUB_VERSION=0.9.2 --build-arg DOCKER_NOTEBOOK_IMAGE=jupyter/r-notebook:r-3.6.3 singleuser   

```

and then

```auto
docker-compose up -d --build

```

When I enter the jupyterhub I was suprised to find a new UX:

 ![Screenshot 2022-10-13 at 07.58.55](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/1/147c2236cac5a5daebd60246b2904bbf7ce3152f.jpeg)

When I switched back to the standard Dockerfile for singleuser i.e.

```auto
make notebook_image

```

with DOCKER\_NOTEBOOK\_IMAGE=jupyter/r-notebook:r-3.6.3  
I get the “old” UX back:

 ![Screenshot 2022-10-13 at 09.02.09](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/d/db19fcac2ad9523eeda7b5ab97bff8910fa3539c.jpeg)

So, little bit offtopic:  
How is it possible to switch between the two different UX?  
Does it depend on DOCKER\_NOTEBOOK\_IMAGE=jupyter/r-notebookXXXXX?

TIA,  
Alex

---

<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:** [October 13, 2022, 1:54pm UTC](https://discourse.jupyter.org/t/how-to-add-additional-packages-to-r/16258/4 "2022-10-13T13:54:45Z")

</div>

`jupyterlab` running on `jupyter_server` has been the default UI for some years at this point. At present, it also serves the classic UI, which can be started from the URL `/tree`.

When opening `jupyterlab`, you can use the main menu to get to _Help » Launch Classic Notebook_.

You can pre-configure launching `/tree` in `~/.jupyter/jupyter_config.json#ServerApp/default_url`, a la:

```auto
{
  "ServerApp": {
    "default_url": "/tree"
  }
}

```
