Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

Goal: Detail how to update an R Conda environment so it can be used as a kernel within ARCC’s Jupyter service.



General Process

The general process involves updating the conda environment to include kernel related packages, and then configuring the kernel spec to allow it to be picked up by the Jupyter service.

  1. Activate you R Conda Environment.

  2. Start R.

  3. Install the IRkernel package.

  4. Exit R.

  5. Deactivate your Conda environment.

  6. Copy the created kernelspec into your home .local/share/jupyter/kernels/ folder.

  7. Update the kernel.json.


Install the IRkernel package

Activate you R Conda Environment and start R.

[salexan5@mblog2 ~]$ module load miniconda3/24.3.0
[salexan5@mblog2 ~]$ conda activate /project/arcc/software/conda-envs/r_4.3.3_env/
(/project/arcc/software/conda-envs/r_4.3.3_env) [salexan5@mblog2 ~]$ R
> install.packages('IRkernel')
...
also installing the dependencies ‘fastmap’, ‘fansi’, ‘utf8’, ‘htmltools’, ‘pillar’, ‘base64enc’, ‘repr’, ‘evaluate’, ‘IRdisplay’, ‘pbdZMQ’, ‘crayon’, ‘jsonlite’, ‘uuid’, ‘digest’
...
* DONE (IRkernel)

Created kernelspec folder

Installing the IRkernel package will create a kernel spec that we can use.

This can be found under the Conda environment location, under: lib/R/library/IRkernel/kernelspec/

[salexan5@mblog2 ~]$ ls /project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library/IRkernel/kernelspec/
kernel.js  kernel.json  logo-64x64.png  logo-svg.svg
[salexan5@mblog2 ~]$ cat /project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library/IRkernel/kernelspec/kernel.json
{"argv": ["R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
 "display_name":"R",
 "language":"R"
}

Configure Your Jupyter Environment

If you haven’t used the Jupyter service, then you might not have, and thus will need to create the following folders:

.local/share/jupyter/kernels/

Copy the created kernelspec into your home:

[salexan5@mblog2 ~]$ cd .local/share/jupyter/kernels/
[salexan5@mblog2 kernel]$ mkdir r_4.3.3
[salexan5@mblog2 kernel]$ cd r_4.3.3
[salexan5@mblog2 r_4.3.3]$ cp /project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library/IRkernel/kernelspec/* .

Update the kernel.json file to:

  • point to the Conda environment’s version of R.

  • give this kernel a unique display name.

[salexan5@mblog2 r_4.3.3]$ cat kernel.json
{"argv": ["/project/arcc/software/conda-envs/r_4.3.3_env/bin/R", "--slave", "-e", "IRkernel::main()", "--args", "{connection_file}"],
 "display_name":"R_4.3.3 (local)",
 "language":"R"
}

Start Jupyter

From OnDemand start a Jupyter session.

Notice how the newly configured kernel is available.

image-20240731-140000.png

Within a Notebook

Within a cell try:

.libPaths()
# Cell Output:
'/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library'
write.table(installed.packages()[,c(1,2,3:4)])
# Cell Output:
"Package" "LibPath" "Version" "Priority"
"base" "base" "/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library" "4.3.3" "base"
...
"vctrs" "vctrs" "/cluster/medbow/project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library" "0.6.5" NA

Note the library path is that of the Conda environment: /project/arcc/software/conda-envs/r_4.3.3_env/lib/R/library


 

  • No labels