footprint
An R package to calculate carbon footprints from air travel based on IATA airport codes or latitude and longitude.
https://github.com/acircleda/footprint
Category: Emissions
Sub Category: Carbon Intensity and Accounting
Last synced: about 10 hours ago
JSON representation
Repository metadata
An R package to calculate carbon footprints from air travel based on IATA airport codes or latitude and longitude.
- Host: GitHub
- URL: https://github.com/acircleda/footprint
- Owner: acircleda
- License: cc0-1.0
- Created: 2020-12-07T13:39:28.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-31T20:17:12.000Z (over 1 year ago)
- Last Synced: 2025-11-18T18:05:10.216Z (about 1 month ago)
- Language: R
- Homepage:
- Size: 8.4 MB
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE.md
README.Rmd
---
output: github_document
---
[](https://github.com/acircleda/footprint/actions)
[](https://CRAN.R-project.org/package=footprint)
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# footprint
The goal of footprint is to calculate carbon footprints from air travel based on IATA airport codes or latitude and longitude.
## Installation
You can install the development version from [GitHub](https://github.com/) with:
```{r, warning=FALSE, message=FALSE, error=FALSE, eval=FALSE}
# install.packages("remotes")
remotes::install_github("acircleda/footprint")
```
## Data and Methodology
Package `footprint` uses the the Haversine great-circle distance formula
to calculate distance between airports or distance between latitude and
longitude pairs. This distance is then used to derive a carbon footprint
estimate, which is based on conversion factors from the Department for
Environment, Food & Rural Affairs (UK) 2019 Greenhouse Gas Conversion
Factors for Business Travel (air):
.
## Example Usage
Load `footprint` using
```{r}
library(footprint)
library(tidyverse)
```
### Using Airport Codes
You can use pairs of three-letter IATA airport codes to calculate distance. This function uses the [`airportr`](https://github.com/dshkol/airportr) package, which contains the data and does the work of getting the distance between airports. *Note*: the `airportr` package offers a number of useful functions for looking up airports by city or name and getting the IATA airport codes.
#### Calculating a Single Trip
The example below calculates a simple footprint estimation for an economy flight from Los Angeles International (LAX) to Heathrow (LHR). The estimate will be in CO~2~e (carbon dioxide equivalent, including radiative forcing). The output is always in kilograms.
```{r, warning=FALSE, message=FALSE, error=FALSE}
airport_footprint("LAX", "LHR", "Economy", "co2e")
```
If there is a layover in Chicago, you could calculate each leg of the trip as follows:
```{r}
airport_footprint("LAX", "ORD", "Economy", "co2e") +
airport_footprint("ORD", "LHR", "Economy", "co2e")
```
#### Calculating More than One Trip
We can calculate the footprint for multiple itineraries at the same time and add to an existing data frame using `mutate`. Here is some example data:
```{r}
library(tibble)
travel_data <- tibble(
name = c("Mike", "Will", "Elle"),
from = c("LAX", "LGA", "TYS"),
to = c("PUS", "LHR", "TPA")
)
```
```{r echo=FALSE, message=FALSE, warning=FALSE}
library(dplyr)
travel_data |>
knitr::kable()
```
Here is how you can take the `from` and `to` data and calculate emissions for each trip. The following function calculates an estimate for CO~2~ (carbon dioxide with radiative forcing).
```{r eval=FALSE, message=FALSE, warning=FALSE, include=FALSE}
travel_data |>
rowwise() |>
mutate(emissions = airport_footprint(from, to, "Economy", output = "co2"))
```
```{r echo=FALSE}
travel_data |>
rowwise() |>
mutate(emissions = airport_footprint(from, to, "Economy", output = "co2")) |>
knitr::kable()
```
#### Calculating More than One Trip and Different years
We can calculate the footprint for multiple itineraries at the same time and add to an existing data frame using `mutate`. Here is some example data:
```{r}
library(tibble)
travel_data <- tibble(
name = c("Mike", "Will", "Elle", "Elle"),
from = c("LAX", "LGA", "TYS", "TYS"),
to = c("PUS", "LHR", "TPA", "TPA"),
date = c("2024-04-05", "2023-04-02", "2024-06-12", "2019-06-12")
)
```
```{r eval=FALSE, message=FALSE, warning=FALSE, include=FALSE}
travel_data |>
rowwise() |>
mutate(emissions = airport_footprint(from, to, "Economy", output = "co2", year=year(date)))
```
```{r echo=FALSE}
travel_data |>
rowwise() |>
mutate(emissions = airport_footprint(from, to, "Economy", output = "co2", year=year(date))) |>
knitr::kable()
```
## From Latitude and Longitude
If you have a list of cities, it might be easier to calculate emissions based on longitude and latitude rather than trying to locate the airports used. For example, one could take city and state data and join that with data from `maps::us.cities` to quickly get latitude and longitude. They can then use the `latlong_footprint()` function to easily calculate emissions based on either a single itinerary or multiple itineraries:
### Calculating a Single Trip
The following example calculates the footprint of a flight from Los Angeles (34.052235, -118.243683) to Busan, South Korea (35.179554, 129.075638). It assumes an average passenger (no `flightClass` argument is included) and its output will be in kilograms of CO~2~e (the default)
```{r}
latlong_footprint(34.052235, -118.243683, 35.179554, 129.075638)
```
### Calculating Multiple Trips
You can use `mutate` to calculate emissions based on a dataframe of latitude and longitude pairs.
Here is some example data:
```{r}
travel_data2 <- tribble(~name, ~departure_lat, ~departure_long, ~arrival_lat, ~arrival_long,
# Los Angeles -> Busan
"Mike", 34.052235, -118.243683, 35.179554, 129.075638,
# New York -> London
"Will", 40.712776, -74.005974, 51.52, -0.10)
```
```{r echo=FALSE}
travel_data2 |> knitr::kable()
```
And here is code to apply it to a dataframe:
```{r eval=FALSE, include=TRUE}
travel_data2 |>
rowwise() |>
mutate(emissions = latlong_footprint(departure_lat,
departure_long,
arrival_lat,
arrival_long))
```
```{r echo=FALSE}
travel_data2 |>
rowwise() |>
mutate(emissions = latlong_footprint(departure_lat,
departure_long,
arrival_lat,
arrival_long)) |>
knitr::kable()
```
Owner metadata
- Name: Anthony Schmidt
- Login: acircleda
- Email:
- Kind: user
- Description:
- Website:
- Location:
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/51770624?u=b9e7f6b6fa6d4d31cfa1e1738f6fc8b7e542ba3d&v=4
- Repositories: 5
- Last ynced at: 2023-02-28T07:42:56.132Z
- Profile URL: https://github.com/acircleda
GitHub Events
Total
- Watch event: 2
Last Year
- Watch event: 2
Committers metadata
Last synced: 3 days ago
Total Commits: 61
Total Committers: 4
Avg Commits per committer: 15.25
Development Distribution Score (DDS): 0.525
Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0
| Name | Commits | |
|---|---|---|
| kkulma | k****a@g****m | 29 |
| acircleda | a****n@y****m | 25 |
| Your | y****l@e****m | 6 |
| Anthony Schmidt | 5****a | 1 |
Issue and Pull Request metadata
Last synced: 3 months ago
Total issues: 2
Total pull requests: 9
Average time to close issues: 1 day
Average time to close pull requests: 1 day
Total issue authors: 2
Total pull request authors: 2
Average comments per issue: 1.0
Average comments per pull request: 0.44
Merged pull request: 9
Bot issues: 0
Bot pull requests: 0
Past year issues: 0
Past year pull requests: 1
Past year average time to close issues: N/A
Past year average time to close pull requests: 5 days
Past year issue authors: 0
Past year pull request authors: 1
Past year average comments per issue: 0
Past year average comments per pull request: 3.0
Past year merged pull request: 1
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- sgichuki (1)
- lilyclements (1)
Top Pull Request Authors
- acircleda (6)
- KKulma (4)
Top Issue Labels
Top Pull Request Labels
Package metadata
- Total packages: 1
-
Total downloads:
- cran: 244 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 2
- Total maintainers: 1
cran.r-project.org: footprint
Calculate Air Travel Emissions
- Homepage: https://github.com/acircleda/footprint
- Documentation: http://cran.r-project.org/web/packages/footprint/footprint.pdf
- Licenses: CC0
- Latest release: 0.2 (published over 1 year ago)
- Last Synced: 2025-12-15T07:16:06.562Z (11 days ago)
- Versions: 2
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 244 Last month
-
Rankings:
- Stargazers count: 14.562%
- Forks count: 28.83%
- Dependent packages count: 29.797%
- Dependent repos count: 35.455%
- Average: 36.586%
- Downloads: 74.288%
- Maintainers (1)
Dependencies
- R >= 2.10 depends
- airportr * imports
- dplyr * imports
- magrittr * imports
- rlang * imports
- covr * suggests
- devtools * suggests
- knitr * suggests
- rmarkdown * suggests
- testthat >= 2.1.0 suggests
- tibble * suggests
- actions/cache v2 composite
- actions/checkout v4 composite
- actions/upload-artifact main composite
- r-lib/actions/setup-pandoc v1 composite
- r-lib/actions/setup-r v2 composite
Score: 9.720765915720834