2DegreesInvesting / tiltIndicator

Indicators for the TILT project
https://2degreesinvesting.github.io/tiltIndicator/
GNU General Public License v3.0
1 stars 1 forks source link

Unexpected error int tiltIndicator's function `emissions_profile` #725

Closed Tilmon closed 4 months ago

Tilmon commented 4 months ago

Hi @maurolepore ,

running the function emissions_profileof tiltIndicator, I encountered an unexpected error, please see screenshot below. Pls also find my R Script here: https://drive.google.com/file/d/1AE-8E6OY22g2CuWnMfNofaI2NOKDcyzf/view?usp=sharing Not an urgent issue because the following functions work but still good to solve as it's our user-facing work.

WORKS:

both <- emissions_profile(companies, products)

both |> unnest_product() 
both |> unnest_company() 

DOESN'T WORK Image

I wonder if it's the case because I use the dataset names from the main page of the article, i.e. companiesand productsinstead of co2. But in that case it would be good to align the wording.

cc' @AnneSchoenauer

maurolepore commented 4 months ago

@Tilmon

It looks like your co2 dataset lacks the expected column isic_4digit. Are you using the correct data?

Here I remove it and get the same error:

devtools::load_all()
#> ℹ Loading tiltIndicator

companies <- example_companies()

products <- example_products()
products$isic_4digit <- NULL

emissions_profile(companies, products)
#> Error in `check_matches_name()` at tiltIndicator/R/pad_column.R:2:3:
#> ! The data lacks a column matching the pattern 'isic_4digit'.
#> ℹ Are you using the correct data?

Created on 2024-02-15 with reprex v2.1.0

Tilmon commented 4 months ago

@maurolepore as you can see in the script I shared, I didn't use any external data. Isn't the co2dataset in the package as toyData?

Tilmon commented 4 months ago

CORRECTION @maurolepore

Apologies, me stupid. The only "problem" is that on this page, the function is specified the following way

emissions_profile(companies, co2, low_threshold = 1/3, high_threshold = 2/3)

while further below on the same page or on the homepage of the article, it's specified the following way

both <- emissions_profile(companies, products)

I.e., the only "issue" is that in one case the toyData are given the name products, in the other co2. Yesterday night, my brain was apparently not able to identify this anymore and I thought that it's two different functions that use different data :) But probably still good to align naming conventions within the same article?

cc' @AnneSchoenauer

maurolepore commented 4 months ago

it happens :-)

I've spent countless nights debugging code that I then fixed in my head while showering the following morning.

It happens less often since I got in the habit of writing reprexes. Writing a reproducible example is a systematic approach to solving problems with a strong focus on the minimal elements required to comuniicate the problem. 90% of the reprexes are never shared because the system is so powerful that people end up finding their own bugs.

A reprex is so important that if you try to open a new issue in tidyverse packages you'll get a pre-populated message asking you to share a reprex:

https://github.com/tidyverse/dplyr/issues/new

Please briefly describe your problem and what output you expect. If you have a question, please don't use this form. Instead, ask on <https://stackoverflow.com/> or <https://community.rstudio.com/>.

Please include a minimal reproducible example (AKA a reprex). If you've never heard of a [reprex](http://reprex.tidyverse.org/) before, start by reading <https://www.tidyverse.org/help/#reprex>.

---

Brief description of the problem

```r
# insert reprex here


Note we have a ds-incubator series about reprex -- but probably the overview is enough: https://youtu.be/erv1yJaNID8?si=NTxiImvqPn567KEt

Actually reprex is so easy to use that even that video might be an overkill, so you may want to first have a look directly at the examples here: https://reprex.tidyverse.org/