pik-piam / quitte

Bits and pieces of code to use with quitte-style data frames
0 stars 10 forks source link

add calc_growthrate function #91

Closed orichters closed 5 months ago

orichters commented 5 months ago

Calculates the growth rate of all variables in '%/yr' and returns a sorted data.frame where each variable name gets [Growth rate] appended.

If, for example, your data contains the data in 2070 and 2060, the growth rate returned for 2070 is calculated as 100 * ((d2070/d2060)^(1/10) - 1). No growth rate can be calculated for the first year of the data. Infinite or undefined values (for example if d2060 = 0) are dropped.

Is the name ok or is there a risk of conflict with functions from other packages?

0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q commented 5 months ago

How about you figure out when you are done and request reviews then, so people do not have to play whack-a-mole …

pweigmann commented 5 months ago

the function is quite slow because of mutate(variable = factor(paste0(.data$variable, " [Growth Rate]"))), maybe operate on levels later in the function

orichters commented 5 months ago

How about you figure out when you are done and request reviews then, so people do not have to play whack-a-mole …

I agree, sorry, using the new IAMC style was an idea that came to my mind only later.

orichters commented 5 months ago

I implemented only.new as in calc_addVariable and filter.function as in read.quitte, with the special case that you can also simply pass a vector c("GDP|PPP") and it will be then use only those. Added some more tests and found some minor bugs (missing ungroup), but should be good to go now.

0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q commented 5 months ago

This would actually be a good candidate to mention in the tutorial, @orichters.

orichters commented 5 months ago

quitte or remindmodel tutorial?