Skip to content

Implementation of CodeCarbon (python) in R-based workflows to measure the energy consumption and carbon footprint of individual snippets of code, scripts, and rendered documents (i.e., Rmd/QMD). This work is a contribution to the pilot Green Digital Skills workshop developed by the Netherlands eScience center.

License

Notifications You must be signed in to change notification settings

UtrechtUniversity/code-carbon-r

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Carbon in R workflows

DOI

This is a demonstration of the implementation of CodeCarbon (python) in R-based workflows to measure the energy consumption of individual snippets of code, scripts, and rendered documents (i.e., Rmd/qmd). This work is an extension to the pilot Green Digital Skills workshop by the Netherlands eScience center.

Usage

The suggested use of this repository starts with making sure that R, RStudio, and python are installed in your computer:

1. Install R and RStudio

Install R and RStudio on your computer if you haven't done so. Note that these demonstrations were conducted under R version 4.4.0 and RStudio 2024.04.0.

2. Install Python and CodeCarbon

Detailed instructions are provided here.

3. Download the material

There are several ways to download the necessary material:

You should now have all the necessary files in your computer with an identical folder structure (described in the following section).

4. Open the project in RStudio

In the main directory, open the file named code-carbon-r.Rproj in RStudio. This will open RStudio in the default working directory of the project. You can now navigate through the folders on the right-bottom panel of R Studio.

Open the R folder. You should now see a file named code-carbon-Quarto.qmd (markdown document with embedded R and python code). Open this file to follow a demonstration of how to use CodeCarbon in R-based workflows. Individual R scripts are found in the R folder, which are sourced into the main document.

5. Re-use the code

There is a sample R script you can reuse and adapt to test your code. Open the file code-carbon-script.R in the R folder. You may download, adapt and re-use this script.

Project Structure

The project structure distinguishes three kinds of folders:

  • read-only (RO): not edited by either code or researcher
  • human-writeable (HW): edited by the researcher only.
  • project-generated (PG): folders generated when running the code; these folders can be deleted or emptied and will be completely reconstituted as the project is run.
.
├── .gitignore
├── CITATION.cff
├── LICENSE
├── README.md
├── code-carbon-r.Rproj
└── R                    <- Source code for this project (HW)

Contact

You can contact me or post a request in this repository in case you encounter any issues.

License

This project is licensed under the terms of the MIT License.

This project structure repository is adapted from the Utrecht University simple R project template, which builds upon the Good Enough Project Cookiecutter template by Barbara Vreede (2019).

About

Implementation of CodeCarbon (python) in R-based workflows to measure the energy consumption and carbon footprint of individual snippets of code, scripts, and rendered documents (i.e., Rmd/QMD). This work is a contribution to the pilot Green Digital Skills workshop developed by the Netherlands eScience center.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published