From 5b7b31014d616908bb82f0356bef71c58e646760 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Dec 2023 15:20:12 +0000 Subject: [PATCH 01/10] Make workflow reproducible --- R/tiltWorkflows-package.R | 7 + inst/WORDLIST | 5 + inst/templates/tiltWorkflows.Rmd | 286 ++++++++++++--------------- vignettes/articles/tiltWorkflows.Rmd | 2 +- 4 files changed, 142 insertions(+), 158 deletions(-) create mode 100644 R/tiltWorkflows-package.R create mode 100644 inst/WORDLIST diff --git a/R/tiltWorkflows-package.R b/R/tiltWorkflows-package.R new file mode 100644 index 00000000..954e342a --- /dev/null +++ b/R/tiltWorkflows-package.R @@ -0,0 +1,7 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +#' @importFrom tiltIndicatorAfter unnest_product +## usethis namespace: end +NULL diff --git a/inst/WORDLIST b/inst/WORDLIST new file mode 100644 index 00000000..7cadbc39 --- /dev/null +++ b/inst/WORDLIST @@ -0,0 +1,5 @@ +CMD +Lifecycle +ORCID +RStudio +funder diff --git a/inst/templates/tiltWorkflows.Rmd b/inst/templates/tiltWorkflows.Rmd index 3ce84f16..31c56f63 100644 --- a/inst/templates/tiltWorkflows.Rmd +++ b/inst/templates/tiltWorkflows.Rmd @@ -1,21 +1,16 @@ --- -title: "tilt workflow" +title: "Creating outputs for all tilt indicators" author: "Kalash Singhal" --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, - comment = "#>", - # FIXME when this file become reproducible - eval = FALSE + comment = "#>" ) ``` -This file uses the output from the tiltIndicatorBefore package as the inputs to -the tiltIndicator and tiltIndicatorAfter packages. This script uses the CSV -files from the tiltIndicatorBefore package to create the final output of the -four indicators. +This workflow creates the output of all tilt indicators. ## Setup @@ -23,214 +18,191 @@ four indicators. library(dplyr, warn.conflicts = FALSE) library(readr, warn.conflicts = FALSE) library(tidyr, warn.conflicts = FALSE) -# devtools::install_github("2DegreesInvesting/tiltIndicatorAfter") -library(tiltIndicatorAfter) -``` - -## tiltIndicatorAfter data common for all indicators - -`ep_companies`, `ei_activities_overview`, `mapper_ep_ei`, `ei_input_data`, and -`isic_4digit_name` are the five datasets which are used as the input for the -tiltIndicatorAfter package. They all are the output from tiltIndicatorBefore -package. These five datasets are used for adding additional data to all the four -indicators (Emissions profile, Emissions profile upstream, Sector profile, -Sector profile upstream). - -```{r} -# ep_companies -europages_campanies <- read_csv("/path/ep_companies.csv") |> - select("company_name", "country", "company_city", "postcode", "address", "main_activity", "companies_id") - -# ecoinvent_activities -ei_activities_ov <- read_csv("/path/ei_activities_overview.csv") - -# matches_mapper -mapper_ep_ei <- read_csv("/path/mapper_ep_ei.csv") +library(fs) +library(tiltWorkflows) -# ecoinvent_inputs -ei_input <- read_csv("/path/ei_input_data.csv") |> - select("input_activity_uuid_product_uuid", "exchange_name", "exchange_unit_name") |> - distinct() +# Helper +tilt_path <- function(...) { + path_home("Downloads", "tilt", ...) +} -# isic_4digit_name -isic_4digit_name <- read_csv("/path/isic_4digit_name.csv") +dir_create(tilt_path("output")) +options(width = 500) ``` -## Emissions profile - -### Load Data +## Data -The input data of Emissions_profile which comes from tiltIndicatorBefore package -becomes the input for the tiltIndicator package. +Here we use toy datasets that you should replace with your real data. ```{r} -# emissions_profile companies -ep_company <- read_csv("/path/emissions_profile_any_companies_ecoinvent.csv") +europages_campanies <- tiltIndicatorAfter::ep_companies |> + # TODO: Ask why the toy data has more columns than we need + select( + "company_name", + "country", + "company_city", + "postcode", + "address", + "main_activity", + "companies_id" + ) + +ecoinvent_activities <- tiltIndicatorAfter::ecoinvent_activities + +ecoinvent_europages <- tiltIndicatorAfter::matches_mapper + +ecoinvent_inputs <- tiltIndicatorAfter::ecoinvent_inputs |> + # TODO: Ask why the toy data has more columns than we need + select( + "input_activity_uuid_product_uuid", + "exchange_name", + "exchange_unit_name" + ) |> + distinct() -# emissions_profile products -ep_product <- read_csv("/path/emissions_profile_products_ecoinvent.csv") +isic_tilt <- tiltIndicatorAfter::isic_tilt_mapper ``` -### Create Emissions_profile product and company level outputs - -The code takes the output of tiltIndicator and use it as an input for the -tiltIndicatorAfter package. +## Emissions profile ```{r} -emissions_profile <- profile_emissions(ep_company, - ep_product, +# Load data specific to this indicator +emissions_profile_any_companies <- read_csv(toy_emissions_profile_any_companies()) +# FIXME User toy_emissions_profile_products_ecoinvent() +# See https://github.com/2DegreesInvesting/tiltToyData/pull/12 +emissions_profile_products <- read_csv(toy_emissions_profile_products()) + +# Create results at product and company level +emissions_profile <- profile_emissions( + emissions_profile_any_companies, + emissions_profile_products, europages_companies = europages_campanies, - ecoinvent_activities = ei_activities_ov, - ecoinvent_europages = mapper_ep_ei, - isic_tilt = isic_4digit_name, + ecoinvent_activities = ecoinvent_activities, + ecoinvent_europages = ecoinvent_europages, + isic_tilt = isic_tilt, low_threshold = 1 / 3, high_threshold = 2 / 3 ) -emissions_profile_at_product_level <- emissions_profile |> unnest_product() -emissions_profile_at_company_level <- emissions_profile |> unnest_company() -``` +emissions_profile_at_product_level <- emissions_profile |> + unnest_product() +emissions_profile_at_product_level -### Save the Emissions profile final results +emissions_profile_at_company_level <- emissions_profile |> + unnest_company() +emissions_profile_at_company_level -```{r} emissions_profile_at_product_level |> - write_csv("/path/emissions_profile_at_product_level.csv") - + write_csv(tilt_path("output", "emissions_profile_at_product_level.csv")) emissions_profile_at_company_level |> - write_csv("/path/emissions_profile_at_company_level.csv") + write_csv(tilt_path("output", "emissions_profile_at_company_level.csv")) ``` -## Emissions Profile Upstream - -### Load Data - -The input data of Emissions Profile Upstream which comes from -tiltIndicatorBefore package becomes the input for the tiltIndicator package. +## Emissions profile upstream ```{r} -epu_company <- read_csv("/path/emissions_profile_any_companies_ecoinvent.csv") - -epu_product <- read_csv("/path/emissions_profile_upstream_products_ecoinvent.csv") -``` - -### Create Emissions profile upstream product and company level outputs - -The code takes the output of tiltIndicator and use it as an input for the -tiltIndicatorAfter package. - -```{r} -emissions_profile_upstream <- profile_emissions_upstream(epu_company, - epu_product, +# Load data specific to this indicator +# FIXME User toy_emissions_profile_upstream_products_ecoinvent() +# See https://github.com/2DegreesInvesting/tiltToyData/pull/12 +emissions_profile_upstream_products <- read_csv(toy_emissions_profile_upstream_products()) + +# Create results at product and company level +emissions_profile_upstream <- profile_emissions_upstream( + emissions_profile_any_companies, + emissions_profile_upstream_products, europages_companies = europages_campanies, - ecoinvent_activities = ei_activities_ov, - ecoinvent_inputs = ei_input, - ecoinvent_europages = mapper_ep_ei, - isic_tilt = isic_4digit_name, + ecoinvent_activities = ecoinvent_activities, + ecoinvent_inputs = ecoinvent_inputs, + ecoinvent_europages = ecoinvent_europages, + isic_tilt = isic_tilt, low_threshold = 1 / 3, high_threshold = 2 / 3 ) -emissions_profile_upstream_at_product_level <- emissions_profile_upstream |> unnest_product() -emissions_profile_upstream_at_company_level <- emissions_profile_upstream |> unnest_company() -``` +emissions_profile_upstream_at_product_level <- emissions_profile_upstream |> + unnest_product() +emissions_profile_upstream_at_product_level -### Save the Emissions profile upstream final results +emissions_profile_upstream_at_company_level <- emissions_profile_upstream |> + unnest_company() +emissions_profile_upstream_at_company_level -```{r} emissions_profile_upstream_at_product_level |> - write_csv("/path/emissions_profile_upstream_at_product_level.csv") - + write_csv(tilt_path("output", "emissions_profile_upstream_at_product_level.csv")) emissions_profile_upstream_at_company_level |> - write_csv("/path/emissions_profile_upstream_at_company_level.csv") + write_csv(tilt_path("output", "emissions_profile_upstream_at_company_level.csv")) ``` -## Sector Profile - -### Load Data - -The input data of Sector Profile which comes from tiltIndicatorBefore package -becomes the input for the tiltIndicator package. - -```{r} -sp_company <- read_csv("/path/sector_profile_companies.csv") - -sp_scenarios <- read_csv("/path/sector_profile_any_scenarios.csv") -``` - -### Create Sector profile product and company level outputs - -The code takes the output of tiltIndicator and use it as an input for the -tiltIndicatorAfter package. +## Sector profile ```{r} -sector_profile <- profile_sector(sp_company, - sp_scenarios, +# Load data specific to this indicator +sector_profile_companies <- read_csv(toy_sector_profile_companies()) +sector_profile_any_scenarios <- read_csv(toy_sector_profile_any_scenarios()) + +# Create results at product and company level +sector_profile <- profile_sector( + sector_profile_companies, + sector_profile_any_scenarios, europages_companies = europages_campanies, - ecoinvent_activities = ei_activities_ov, - ecoinvent_europages = mapper_ep_ei, - isic_tilt = isic_4digit_name, + ecoinvent_activities = ecoinvent_activities, + ecoinvent_europages = ecoinvent_europages, + isic_tilt = isic_tilt, low_threshold = 1 / 3, high_threshold = 2 / 3 ) -sector_profile_at_product_level <- sector_profile |> unnest_product() -sector_profile_at_company_level <- sector_profile |> unnest_company() -``` +sector_profile_at_product_level <- sector_profile |> + unnest_product() +sector_profile_at_product_level -### Save the Sector profile final results +sector_profile_at_company_level <- sector_profile |> + unnest_company() +sector_profile_at_company_level -```{r} sector_profile_at_product_level |> - write_csv("/path/sector_profile_at_product_level.csv") - + write_csv(tilt_path("output", "sector_profile_at_product_level.csv")) sector_profile_at_company_level |> - write_csv("/path/sector_profile_at_company_level.csv") + write_csv(tilt_path("output", "sector_profile_at_company_level.csv")) ``` ## Sector profile upstream -### Load Data - -The input data of Sector profile upstream which comes from tiltIndicatorBefore -package becomes the input for the tiltIndicator package. - ```{r} -spu_company <- read_csv("/path/sector_profile_upstream_companies.csv") - -spu_product <- read_csv("/path/sector_profile_upstream_products.csv") - -spu_scenarios <- read_csv("/path/sector_profile_any_scenarios.csv") -``` - -### Create Sector profile upstream product and company level outputs. - -The code takes the output of tiltIndicator and use it as an input for the -tiltIndicatorAfter package. - -```{r} -sector_profile_upstream <- profile_sector_upstream(spu_company, - spu_scenarios, - spu_product, +# Load data specific to this indicator +sector_profile_upstream_companies <- read_csv(toy_sector_profile_upstream_companies()) +sector_profile_upstream_products <- read_csv(toy_sector_profile_upstream_products()) + +# Create results at product and company level +sector_profile_upstream <- profile_sector_upstream( + sector_profile_upstream_companies, + sector_profile_any_scenarios, + sector_profile_upstream_products, europages_companies = europages_campanies, - ecoinvent_activities = ei_activities_ov, - ecoinvent_inputs = ei_input, - ecoinvent_europages = mapper_ep_ei, - isic_tilt = isic_4digit_name, + ecoinvent_activities = ecoinvent_activities, + ecoinvent_inputs = ecoinvent_inputs, + ecoinvent_europages = ecoinvent_europages, + isic_tilt = isic_tilt, low_threshold = 1 / 3, high_threshold = 2 / 3 ) -sector_profile_upstream_at_product_level <- sector_profile_upstream |> unnest_product() -sector_profile_upstream_at_company_level <- sector_profile_upstream |> unnest_company() -``` +sector_profile_upstream_at_product_level <- sector_profile_upstream |> + unnest_product() +sector_profile_upstream_at_product_level -### Save the Sector profile upstream final results +sector_profile_upstream_at_company_level <- sector_profile_upstream |> + unnest_company() +sector_profile_upstream_at_company_level -```{r} sector_profile_upstream_at_product_level |> - write_csv("/path/sector_profile_upstream_at_product_level.csv") - + write_csv(tilt_path("output", "sector_profile_upstream_at_product_level.csv")) sector_profile_upstream_at_company_level |> - write_csv("/path/sector_profile_upstream_at_company_level.csv") + write_csv(tilt_path("output", "sector_profile_upstream_at_company_level.csv")) +``` + +## Results + +```{r} +dir_tree(tilt_path("output")) ``` diff --git a/vignettes/articles/tiltWorkflows.Rmd b/vignettes/articles/tiltWorkflows.Rmd index a3746e5b..71fef2fb 100644 --- a/vignettes/articles/tiltWorkflows.Rmd +++ b/vignettes/articles/tiltWorkflows.Rmd @@ -1,5 +1,5 @@ --- -title: "tilt workflow" +title: "Creating outputs for all tilt indicators" author: "Kalash Singhal" --- From 470eb59da1aa5c1b5a51ce06a0689cc8a250ffc1 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Dec 2023 15:41:44 +0000 Subject: [PATCH 02/10] Remove needless tidyr --- inst/templates/tiltWorkflows.Rmd | 1 - 1 file changed, 1 deletion(-) diff --git a/inst/templates/tiltWorkflows.Rmd b/inst/templates/tiltWorkflows.Rmd index 31c56f63..0457c109 100644 --- a/inst/templates/tiltWorkflows.Rmd +++ b/inst/templates/tiltWorkflows.Rmd @@ -17,7 +17,6 @@ This workflow creates the output of all tilt indicators. ```{r} library(dplyr, warn.conflicts = FALSE) library(readr, warn.conflicts = FALSE) -library(tidyr, warn.conflicts = FALSE) library(fs) library(tiltWorkflows) From 1b863ca24e8423fd0fcb2565c736ae04377db458 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Dec 2023 15:56:39 +0000 Subject: [PATCH 03/10] Use a simpler path --- inst/templates/tiltWorkflows.Rmd | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/inst/templates/tiltWorkflows.Rmd b/inst/templates/tiltWorkflows.Rmd index 0457c109..f26397e0 100644 --- a/inst/templates/tiltWorkflows.Rmd +++ b/inst/templates/tiltWorkflows.Rmd @@ -25,7 +25,7 @@ tilt_path <- function(...) { path_home("Downloads", "tilt", ...) } -dir_create(tilt_path("output")) +dir_create(tilt_path()) options(width = 500) ``` @@ -92,9 +92,9 @@ emissions_profile_at_company_level <- emissions_profile |> emissions_profile_at_company_level emissions_profile_at_product_level |> - write_csv(tilt_path("output", "emissions_profile_at_product_level.csv")) + write_csv(tilt_path("emissions_profile_at_product_level.csv")) emissions_profile_at_company_level |> - write_csv(tilt_path("output", "emissions_profile_at_company_level.csv")) + write_csv(tilt_path("emissions_profile_at_company_level.csv")) ``` ## Emissions profile upstream @@ -127,9 +127,9 @@ emissions_profile_upstream_at_company_level <- emissions_profile_upstream |> emissions_profile_upstream_at_company_level emissions_profile_upstream_at_product_level |> - write_csv(tilt_path("output", "emissions_profile_upstream_at_product_level.csv")) + write_csv(tilt_path("emissions_profile_upstream_at_product_level.csv")) emissions_profile_upstream_at_company_level |> - write_csv(tilt_path("output", "emissions_profile_upstream_at_company_level.csv")) + write_csv(tilt_path("emissions_profile_upstream_at_company_level.csv")) ``` ## Sector profile @@ -160,9 +160,9 @@ sector_profile_at_company_level <- sector_profile |> sector_profile_at_company_level sector_profile_at_product_level |> - write_csv(tilt_path("output", "sector_profile_at_product_level.csv")) + write_csv(tilt_path("sector_profile_at_product_level.csv")) sector_profile_at_company_level |> - write_csv(tilt_path("output", "sector_profile_at_company_level.csv")) + write_csv(tilt_path("sector_profile_at_company_level.csv")) ``` ## Sector profile upstream @@ -195,9 +195,9 @@ sector_profile_upstream_at_company_level <- sector_profile_upstream |> sector_profile_upstream_at_company_level sector_profile_upstream_at_product_level |> - write_csv(tilt_path("output", "sector_profile_upstream_at_product_level.csv")) + write_csv(tilt_path("sector_profile_upstream_at_product_level.csv")) sector_profile_upstream_at_company_level |> - write_csv(tilt_path("output", "sector_profile_upstream_at_company_level.csv")) + write_csv(tilt_path("sector_profile_upstream_at_company_level.csv")) ``` ## Results From 01f4e64297a0212671bc68c3f9edee2621cb90a1 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Dec 2023 16:01:52 +0000 Subject: [PATCH 04/10] wip --- inst/templates/tiltWorkflows.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/templates/tiltWorkflows.Rmd b/inst/templates/tiltWorkflows.Rmd index f26397e0..06023f94 100644 --- a/inst/templates/tiltWorkflows.Rmd +++ b/inst/templates/tiltWorkflows.Rmd @@ -203,5 +203,5 @@ sector_profile_upstream_at_company_level |> ## Results ```{r} -dir_tree(tilt_path("output")) +dir_tree(tilt_path()) ``` From 64ab7a5d481154b2c662810cfa17a354af0f5bcd Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Dec 2023 16:10:06 +0000 Subject: [PATCH 05/10] wip --- inst/templates/tiltWorkflows.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/templates/tiltWorkflows.Rmd b/inst/templates/tiltWorkflows.Rmd index 06023f94..c116488a 100644 --- a/inst/templates/tiltWorkflows.Rmd +++ b/inst/templates/tiltWorkflows.Rmd @@ -35,7 +35,6 @@ Here we use toy datasets that you should replace with your real data. ```{r} europages_campanies <- tiltIndicatorAfter::ep_companies |> - # TODO: Ask why the toy data has more columns than we need select( "company_name", "country", @@ -51,7 +50,6 @@ ecoinvent_activities <- tiltIndicatorAfter::ecoinvent_activities ecoinvent_europages <- tiltIndicatorAfter::matches_mapper ecoinvent_inputs <- tiltIndicatorAfter::ecoinvent_inputs |> - # TODO: Ask why the toy data has more columns than we need select( "input_activity_uuid_product_uuid", "exchange_name", @@ -69,6 +67,7 @@ isic_tilt <- tiltIndicatorAfter::isic_tilt_mapper emissions_profile_any_companies <- read_csv(toy_emissions_profile_any_companies()) # FIXME User toy_emissions_profile_products_ecoinvent() # See https://github.com/2DegreesInvesting/tiltToyData/pull/12 +# https://github.com/2DegreesInvesting/tiltWorkflows/issues/9 emissions_profile_products <- read_csv(toy_emissions_profile_products()) # Create results at product and company level @@ -103,6 +102,7 @@ emissions_profile_at_company_level |> # Load data specific to this indicator # FIXME User toy_emissions_profile_upstream_products_ecoinvent() # See https://github.com/2DegreesInvesting/tiltToyData/pull/12 +# https://github.com/2DegreesInvesting/tiltWorkflows/issues/9 emissions_profile_upstream_products <- read_csv(toy_emissions_profile_upstream_products()) # Create results at product and company level From 1406008b73d8241b8f2c99048dc618b552c1e121 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Thu, 7 Dec 2023 19:42:10 +0000 Subject: [PATCH 06/10] wip --- inst/templates/tiltWorkflows.Rmd | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/inst/templates/tiltWorkflows.Rmd b/inst/templates/tiltWorkflows.Rmd index c116488a..cccf3e22 100644 --- a/inst/templates/tiltWorkflows.Rmd +++ b/inst/templates/tiltWorkflows.Rmd @@ -25,7 +25,7 @@ tilt_path <- function(...) { path_home("Downloads", "tilt", ...) } -dir_create(tilt_path()) +dir_create(tilt_path("output")) options(width = 500) ``` @@ -91,9 +91,9 @@ emissions_profile_at_company_level <- emissions_profile |> emissions_profile_at_company_level emissions_profile_at_product_level |> - write_csv(tilt_path("emissions_profile_at_product_level.csv")) + write_csv(tilt_path("output", "emissions_profile_at_product_level.csv")) emissions_profile_at_company_level |> - write_csv(tilt_path("emissions_profile_at_company_level.csv")) + write_csv(tilt_path("output", "emissions_profile_at_company_level.csv")) ``` ## Emissions profile upstream @@ -127,9 +127,9 @@ emissions_profile_upstream_at_company_level <- emissions_profile_upstream |> emissions_profile_upstream_at_company_level emissions_profile_upstream_at_product_level |> - write_csv(tilt_path("emissions_profile_upstream_at_product_level.csv")) + write_csv(tilt_path("output", "emissions_profile_upstream_at_product_level.csv")) emissions_profile_upstream_at_company_level |> - write_csv(tilt_path("emissions_profile_upstream_at_company_level.csv")) + write_csv(tilt_path("output", "emissions_profile_upstream_at_company_level.csv")) ``` ## Sector profile @@ -160,9 +160,9 @@ sector_profile_at_company_level <- sector_profile |> sector_profile_at_company_level sector_profile_at_product_level |> - write_csv(tilt_path("sector_profile_at_product_level.csv")) + write_csv(tilt_path("output", "sector_profile_at_product_level.csv")) sector_profile_at_company_level |> - write_csv(tilt_path("sector_profile_at_company_level.csv")) + write_csv(tilt_path("output", "sector_profile_at_company_level.csv")) ``` ## Sector profile upstream @@ -195,13 +195,13 @@ sector_profile_upstream_at_company_level <- sector_profile_upstream |> sector_profile_upstream_at_company_level sector_profile_upstream_at_product_level |> - write_csv(tilt_path("sector_profile_upstream_at_product_level.csv")) + write_csv(tilt_path("output", "sector_profile_upstream_at_product_level.csv")) sector_profile_upstream_at_company_level |> - write_csv(tilt_path("sector_profile_upstream_at_company_level.csv")) + write_csv(tilt_path("output", "sector_profile_upstream_at_company_level.csv")) ``` ## Results ```{r} -dir_tree(tilt_path()) +dir_tree(tilt_path("output")) ``` From 0a610edc2c2f9c2f776eee5c35eaa48e13925307 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Fri, 8 Dec 2023 07:03:54 +0000 Subject: [PATCH 07/10] wip --- inst/templates/tiltWorkflows.Rmd | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/inst/templates/tiltWorkflows.Rmd b/inst/templates/tiltWorkflows.Rmd index cccf3e22..1d281d87 100644 --- a/inst/templates/tiltWorkflows.Rmd +++ b/inst/templates/tiltWorkflows.Rmd @@ -14,19 +14,20 @@ This workflow creates the output of all tilt indicators. ## Setup -```{r} +```{r global} library(dplyr, warn.conflicts = FALSE) library(readr, warn.conflicts = FALSE) library(fs) library(tiltWorkflows) -# Helper +# Help create paths under ~/Downloads/tilt/ tilt_path <- function(...) { path_home("Downloads", "tilt", ...) } - +# Create a folder to save results dir_create(tilt_path("output")) -options(width = 500) +# Read data quietly and print wider data frames +options(readr.show_col_types = FALSE, width = 500) ``` ## Data From 16b6ca11b3d2cbd0536e35a66b275349a0d8bffd Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Fri, 8 Dec 2023 07:14:24 +0000 Subject: [PATCH 08/10] wip --- .gitignore | 1 + inst/templates/tiltWorkflows.Rmd | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 513025f9..ac35bb09 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .Rproj.user docs +inst/templates/tiltWorkflows.html diff --git a/inst/templates/tiltWorkflows.Rmd b/inst/templates/tiltWorkflows.Rmd index 1d281d87..c5ec1eac 100644 --- a/inst/templates/tiltWorkflows.Rmd +++ b/inst/templates/tiltWorkflows.Rmd @@ -26,8 +26,8 @@ tilt_path <- function(...) { } # Create a folder to save results dir_create(tilt_path("output")) -# Read data quietly and print wider data frames -options(readr.show_col_types = FALSE, width = 500) +# Print wider data frames +options(width = 500) ``` ## Data From ee1d704e7fe157851dfba6e41ec7b96a8e3f791e Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Fri, 8 Dec 2023 13:20:00 +0000 Subject: [PATCH 09/10] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ac35bb09..76da7978 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .Rproj.user docs +inst/templates/tilt-profiles.html inst/templates/tiltWorkflows.html From ac38c206d9cc25a0af5d7225d0fa0b78a97cde61 Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Fri, 8 Dec 2023 13:20:10 +0000 Subject: [PATCH 10/10] Use partial matching --- inst/templates/tilt-profiles.Rmd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inst/templates/tilt-profiles.Rmd b/inst/templates/tilt-profiles.Rmd index c5ec1eac..4c21859a 100644 --- a/inst/templates/tilt-profiles.Rmd +++ b/inst/templates/tilt-profiles.Rmd @@ -58,7 +58,7 @@ ecoinvent_inputs <- tiltIndicatorAfter::ecoinvent_inputs |> ) |> distinct() -isic_tilt <- tiltIndicatorAfter::isic_tilt_mapper +isic <- tiltIndicatorAfter::isic_tilt_mapper ``` ## Emissions profile @@ -78,7 +78,7 @@ emissions_profile <- profile_emissions( europages_companies = europages_campanies, ecoinvent_activities = ecoinvent_activities, ecoinvent_europages = ecoinvent_europages, - isic_tilt = isic_tilt, + isic = isic, low_threshold = 1 / 3, high_threshold = 2 / 3 ) @@ -114,7 +114,7 @@ emissions_profile_upstream <- profile_emissions_upstream( ecoinvent_activities = ecoinvent_activities, ecoinvent_inputs = ecoinvent_inputs, ecoinvent_europages = ecoinvent_europages, - isic_tilt = isic_tilt, + isic = isic, low_threshold = 1 / 3, high_threshold = 2 / 3 ) @@ -147,7 +147,7 @@ sector_profile <- profile_sector( europages_companies = europages_campanies, ecoinvent_activities = ecoinvent_activities, ecoinvent_europages = ecoinvent_europages, - isic_tilt = isic_tilt, + isic = isic, low_threshold = 1 / 3, high_threshold = 2 / 3 ) @@ -182,7 +182,7 @@ sector_profile_upstream <- profile_sector_upstream( ecoinvent_activities = ecoinvent_activities, ecoinvent_inputs = ecoinvent_inputs, ecoinvent_europages = ecoinvent_europages, - isic_tilt = isic_tilt, + isic = isic, low_threshold = 1 / 3, high_threshold = 2 / 3 )