Closed nikosbosse closed 3 days ago
I don't mean to be an agent of chaos but if users can just do class(forecast)
why can't we? Most of the checks could use forecast_sample
etc as well as using what they currently do (i.e sample
). This would mean that those implementing a new forecast class would have one less thing to do.
If we wanted we could have it as not s3 and public but just make it
get_forecast_type <- function(forecast) {
class(forecast)[1]
}
For users who might not know about classes and might want a helper still?
If we wanted to keep the current use couldn't we just regex out the forecast_
(and error if it doesn't have that string?)?
I don't mean to be an agent of chaos but if users can just do class(forecast) why can't we?
Yeah, fair point. I currently went for this implementation:
get_forecast_type <- function(forecast) {
classname <- class(forecast)[1]
if (grepl("forecast_", classname)) {
type <- gsub("forecast_", "", classname)
return(type)
} else {
cli_abort("Input is not a valid forecast object (it's first class should begin with `forecast_`).")
}
}
I guess it's a bit of a question whether the forecast type should be "quantile" or "forecast_quantile". It feels to me that "quantile" as the forecast type has a bit more conceptual clarity. Using "forecast_quantile" might be a bit clearer code-wise.
I implemented it this way as it's just a drop-in replacement that doesn't require any additional changes to the code. Also happy to get rid of the gsub
thing, but I thought maybe let's go with this for now and maybe change it later?
Yes agree sounds like a good idea
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 97.31%. Comparing base (
3d4a0ce
) to head (7f8e9a3
). Report is 7 commits behind head on main.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Description
This PR closes #887.
This function makes
get_forecast_type()
an internal function. I think it's fine to have this function be internal - users can just callclass(forecast)
to check the type of their forecast.to do: update manuscript and info graphics to reflect that change.
Checklist
lintr::lint_package()
to check for style issues introduced by my changes.