cowfootR: An R Package for Dairy Farm Carbon Footprint Assessment

cowfootR: An R Package for Dairy Farm Carbon Footprint Assessment - Published in JOSS (2026)

https://github.com/juanmarcosmoreno-arch/cowfootr

Science Score: 90.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in JOSS metadata
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software
Last synced: 2 months ago · JSON representation

Repository

Tools to Estimate the Carbon Footprint of Dairy Farms

Basic Info
Statistics
  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Created 11 months ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Codemeta

README.Rmd

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# cowfootR 

Tools to estimate the carbon footprint of dairy farms.  
Implements methods based on IDF (International Dairy Federation)  
and IPCC guidelines for greenhouse gas accounting.


[![CRAN status](https://www.r-pkg.org/badges/version/cowfootR)](https://CRAN.R-project.org/package=cowfootR)
[![R-CMD-check](https://github.com/juanmarcosmoreno-arch/cowfootR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/juanmarcosmoreno-arch/cowfootR/actions/workflows/R-CMD-check.yaml)
[![Project Status: Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#maturing)
[![Codecov test coverage](https://codecov.io/gh/juanmarcosmoreno-arch/cowfootR/graph/badge.svg)](https://app.codecov.io/gh/juanmarcosmoreno-arch/cowfootR)


## Overview

`cowfootR` provides a comprehensive toolkit for calculating carbon
footprints of dairy farms following IPCC guidelines
([IPCC 2019 Refinement](https://www.ipcc-nggip.iges.or.jp/public/2019rf/index.html))
and International Dairy Federation guidance for the dairy sector
([IDF Bulletin 520](https://shop.fil-idf.org/products/the-idf-global-carbon-footprint-standard-for-the-dairy-sector?_pos=1&_sid=8a3f414f8&_ss=r)).
The package includes:

- **Individual emission calculations** from enteric fermentation, manure, soil, energy, and inputs
- **Batch processing** capabilities for multiple farms
- **Intensity metrics** per liter of milk and per hectare
- **System boundary flexibility** (farm gate, cradle-to-farm gate, etc.)
- **Excel integration** for data input and report generation

## Installation


```{r eval=FALSE}
install.packages("cowfootR")
```
Or install the development version:
```{r eval=FALSE}
devtools::install_github("juanmarcosmoreno-arch/cowfootR")
```

## Quick Start

Below is a minimal, end-to-end example showing the core workflow of `cowfootR`
for a single dairy farm.

```{r example}
library(cowfootR)

# 1. Define system boundaries
boundaries <- set_system_boundaries("farm_gate")

# 2. Calculate emissions by source
enteric <- calc_emissions_enteric(
  n_animals = 100,
  cattle_category = "dairy_cows",
  boundaries = boundaries
)

manure <- calc_emissions_manure(
  n_cows = 100,
  boundaries = boundaries
)

soil <- calc_emissions_soil(
  n_fertilizer_synthetic = 1500,
  n_excreta_pasture = 5000,
  area_ha = 120,
  boundaries = boundaries
)

energy <- calc_emissions_energy(
  diesel_l = 2000,
  electricity_kwh = 5000,
  boundaries = boundaries
)

inputs <- calc_emissions_inputs(
  conc_kg = 1000,
  fert_n_kg = 500,
  boundaries = boundaries
)

# 3. Aggregate total emissions
total_emissions <- calc_total_emissions(enteric, manure, soil, energy, inputs)
total_emissions

# 4. Intensity metrics
milk_intensity <- calc_intensity_litre(
  total_emissions = total_emissions,
  milk_litres = 750000,
  fat = 4.0,
  protein = 3.3
)
milk_intensity

area_intensity <- calc_intensity_area(
  total_emissions = total_emissions,
  area_total_ha = 120
)
area_intensity
```
**Note on units:**  
All absolute emission results returned by `cowfootR` (reported as kg CO₂eq) correspond to **annual, farm-level emissions** within the defined system boundaries. Intensity metrics are expressed per unit of product (kg CO₂eq per kg FPCM) and per unit of land area (kg CO₂eq per ha), all based on annual data.

## Batch processing (typical real-world use)

In practical applications, `cowfootR` is most often used to process data from
multiple farms simultaneously. This is handled through the `calc_batch()`
function, which applies the same methodological workflow across all farms in a
structured dataset.

Below is a minimal example illustrating batch processing for multiple farms.

```{r example_batch}
library(cowfootR)

# Example dataset with two farms
farms <- data.frame(
  FarmID = c("Farm_A", "Farm_B"),
  Year = c(2023, 2023),
  Milk_litres = c(500000, 750000),
  Cows_milking = c(90, 130),
  Area_total_ha = c(110, 160),
  Diesel_litres = c(4000, 6500),
  Electricity_kWh = c(18000, 26000),
  Concentrate_feed_kg = c(120000, 180000),
  stringsAsFactors = FALSE
)

# Define system boundaries
boundaries <- set_system_boundaries("farm_gate")

# Run batch carbon footprint calculation
batch_results <- calc_batch(
  data = farms,
  tier = 2,
  boundaries = boundaries,
  benchmark_region = "uruguay"
)

# Summary of batch processing
batch_results$summary

# Farm-level results
batch_results$farm_results

# Export results to Excel
export_hdc_report(
  batch_results,
  file = "cowfootR_batch_report.xlsx"
)

```
Batch results can be directly exported to an Excel report using
`export_hdc_report()`, facilitating integration with reporting workflows
commonly used by consultants, researchers, and stakeholders.

### Emission Sources Covered

- **Enteric fermentation**: CH₄ from ruminal fermentation
- **Manure management**: CH₄ and N₂O from manure systems
- **Soil emissions**: N₂O from fertilizer application and excreta
- **Energy consumption**: CO₂ from diesel, electricity, and other fuels
- **External inputs**: CO₂eq from feed, fertilizers, and materials

### System Boundaries

```{r boundaries, eval=FALSE}
boundaries_fg <- set_system_boundaries("farm_gate")
boundaries_cfg <- set_system_boundaries("cradle_to_farm_gate")
```

### Intensity Metrics

The package calculates multiple intensity metrics:

- **Per liter of milk**: kg CO₂eq per liter
- **Per kg FPCM**: kg CO₂eq per kg Fat and Protein Corrected Milk
- **Per hectare**: kg CO₂eq per hectare (total and productive area)
- **Land use efficiency**: productive area / total area ratio

## Data Requirements

### Required Columns
- `FarmID`: Unique farm identifier
- `Year`: Year of data collection  
- `Milk_litres`: Annual milk production (liters)
- `Cows_milking`: Number of milking cows
- `Area_total_ha`: Total farm area (hectares)

### Optional Columns
- Animal data: `Cows_dry`, `Heifers_total`, `Calves_total`, `Bulls_total`
- Production: `Fat_percent`, `Protein_percent`, `Milk_yield_kg_cow_year`
- Feed: `MS_intake_cows_milking_kg_day`, `Ym_percent`, `Concentrate_feed_kg`
- Fertilizer: `N_fertilizer_kg`, `N_fertilizer_organic_kg`
- Energy: `Diesel_litres`, `Electricity_kWh`, `Petrol_litres`
- Land use: `Area_productive_ha`, `Pasture_permanent_ha`

Use `cf_download_template()` to get the complete column structure.

## Error Handling

The package includes robust error handling for batch processing:

For batch processing, Excel templates, reporting, and error handling,
please see the package vignettes and the documentation website.

## Contributing

This package is under active development. Please report issues or suggest improvements on [GitHub](https://github.com/juanmarcosmoreno-arch/cowfootR/issues).

## References

- IPCC 2019 Refinement to the 2006 IPCC Guidelines for National Greenhouse Gas Inventories
https://www.ipcc-nggip.iges.or.jp/public/2019rf/index.html
- International Dairy Federation (IDF). 2022. The IDF global Carbon Footprint standard for the dairy sector
https://shop.fil-idf.org/products/the-idf-global-carbon-footprint-standard-for-the-dairy-sector?_pos=1&_sid=8a3f414f8&_ss=r
- FAO. 2010. Greenhouse Gas Emissions from the Dairy Sector
https://www.fao.org/4/k7930e/k7930e00.pdf

## License

MIT License © 2025 Juan Moreno

[![pkgdown site](https://img.shields.io/badge/docs-pkgdown-blue.svg)](https://juanmarcosmoreno-arch.github.io/cowfootR/)

Owner

  • Login: juanmarcosmoreno-arch
  • Kind: user

JOSS Publication

cowfootR: An R Package for Dairy Farm Carbon Footprint Assessment
Published
May 07, 2026
Volume 11, Issue 121, Page 9572
Authors
Juan M. Moreno ORCID
Conaprole, Uruguay
Editor
Kalyn Dorheim ORCID
Tags
carbon footprint dairy farming greenhouse gas emissions sustainability

CodeMeta (codemeta.json)

{
  "@context": "https://doi.org/10.5063/schema/codemeta-2.0",
  "@type": "SoftwareSourceCode",
  "identifier": "cowfootR",
  "description": "Provides functions to calculate the carbon footprint of dairy farms based on based on methodologies of the International Dairy Federation and the Intergovernmental Panel on Climate Change methodologies. Includes tools for single-farm and batch analysis, report generation, and visualization.",
  "name": "cowfootR: Tools to Estimate the Carbon Footprint of Dairy Farms",
  "relatedLink": "https://juanmarcosmoreno-arch.github.io/cowfootR/",
  "codeRepository": "https://github.com/juanmarcosmoreno-arch/cowfootR",
  "issueTracker": "https://github.com/juanmarcosmoreno-arch/cowfootR/issues",
  "license": "https://spdx.org/licenses/MIT",
  "version": "0.0.2",
  "programmingLanguage": {
    "@type": "ComputerLanguage",
    "name": "R",
    "url": "https://r-project.org"
  },
  "runtimePlatform": "R version 4.5.1 (2025-06-13)",
  "author": [
    {
      "@type": "Person",
      "givenName": "Juan",
      "familyName": "Moreno",
      "email": "juanmarcosmoreno@gmail.com"
    }
  ],
  "maintainer": [
    {
      "@type": "Person",
      "givenName": "Juan",
      "familyName": "Moreno",
      "email": "juanmarcosmoreno@gmail.com"
    }
  ],
  "softwareSuggestions": [
    {
      "@type": "SoftwareApplication",
      "identifier": "testthat",
      "name": "testthat",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=testthat"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "readxl",
      "name": "readxl",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=readxl"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "plotly",
      "name": "plotly",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=plotly"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "gt",
      "name": "gt",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=gt"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "knitr",
      "name": "knitr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=knitr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "rmarkdown",
      "name": "rmarkdown",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=rmarkdown"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "dplyr",
      "name": "dplyr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=dplyr"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "ggplot2",
      "name": "ggplot2",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=ggplot2"
    },
    {
      "@type": "SoftwareApplication",
      "identifier": "tidyr",
      "name": "tidyr",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=tidyr"
    }
  ],
  "softwareRequirements": {
    "1": {
      "@type": "SoftwareApplication",
      "identifier": "R",
      "name": "R",
      "version": ">= 4.1.0"
    },
    "2": {
      "@type": "SoftwareApplication",
      "identifier": "writexl",
      "name": "writexl",
      "provider": {
        "@id": "https://cran.r-project.org",
        "@type": "Organization",
        "name": "Comprehensive R Archive Network (CRAN)",
        "url": "https://cran.r-project.org"
      },
      "sameAs": "https://CRAN.R-project.org/package=writexl"
    },
    "SystemRequirements": null
  },
  "fileSize": "501.779KB",
  "releaseNotes": "https://github.com/juanmarcosmoreno-arch/cowfootR/blob/main/NEWS.md",
  "readme": "https://github.com/juanmarcosmoreno-arch/cowfootR/blob/master/README.md",
  "contIntegration": "https://github.com/juanmarcosmoreno-arch/cowfootR/actions/workflows/R-CMD-check.yaml",
  "developmentStatus": [
    "https://www.repostatus.org/#active",
    "https://lifecycle.r-lib.org/articles/stages.html#maturing"
  ]
}

GitHub Events

Total
  • Delete event: 1
  • Issues event: 4
  • Issue comment event: 8
  • Push event: 62
  • Create event: 5
Last Year
  • Delete event: 1
  • Issues event: 4
  • Issue comment event: 8
  • Push event: 62
  • Create event: 5

Committers

Last synced: 2 months ago

All Time
  • Total Commits: 90
  • Total Committers: 1
  • Avg Commits per committer: 90.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 90
  • Committers: 1
  • Avg Commits per committer: 90.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Juan Moreno j****o@g****m 90

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 485 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 2
  • Total maintainers: 1
cran.r-project.org: cowfootR

Dairy Farm Carbon Footprint Assessment

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 485 Last month
Rankings
Dependent packages count: 25.4%
Dependent repos count: 31.3%
Average: 47.4%
Downloads: 85.5%
Maintainers (1)
Last synced: 2 months ago