
Track emissions for a single block of code
Source:R/with-emissions-tracked.R
with_emissions_tracked.RdTrack emissions for a single block of code
Arguments
- expr
Code to run and measure.
- country_iso_code
3-letter ISO code used to look up grid carbon intensity, e.g.
"USA". Calllist_carbon_tracker_countries()for the supported codes.- ...
Passed to
carbon_tracker().
Value
A carbon_emissions_result: $result holds the value of expr,
$emissions holds the carbon_emissions object.
Examples
# \donttest{
# Requires codecarbon to be installed (setup_carbon_tracker()); not run
# on CRAN's check machines, which don't have it.
if (carbon_tracker_ready()) {
out <- with_emissions_tracked(
Sys.sleep(1),
country_iso_code = "USA",
output_dir = tempdir()
)
print(out)
}
# }