-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #585: allow users to specify columns and forecast unit in as_forecast()
#641
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #641 +/- ##
==========================================
+ Coverage 87.53% 87.73% +0.20%
==========================================
Files 21 21
Lines 1757 1786 +29
==========================================
+ Hits 1538 1567 +29
Misses 219 219 ☔ View full report in Codecov by Sentry. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from my comment about the default args I like this as is. Happy to watch the discussion play out.
This comment was marked as resolved.
This comment was marked as resolved.
R/validate.R
Outdated
as_forecast.default <- function(data, | ||
observed = NULL, | ||
predicted = NULL, | ||
model = NULL, | ||
forecast_unit = NULL, | ||
quantile_level = NULL, | ||
sample_id = NULL, | ||
...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to accept other arguments by ...
? In case users misspecify the argument name, it seems better to me to omit ...
to decline every argument.
Is it better to include type = NULL
argument if the user want to be sure about the forecast type? For example, if type="quantile"
is specified, we raise an error if the quantile_level
argument is not given, or simply raise an error if the returned class is not matched with this argument. I think this is related to #603.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah those are good points!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as_forecast.default()
needs ...
because the generic has it and the method and the generic always need to have the same arguments. But I like the idea of having a forecast_type
argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that true for ...
args though? I'm not sure it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked, it's true for ...
args as well:
checking S3 generic/method consistency (1.7s)
as_forecast:
function(data, ...)
as_forecast.default:
function(data, forecast_unit, forecast_type, observed, predicted,
model, quantile_level, sample_id)
See section ‘Generic functions and methods’ in the ‘Writing R
Extensions’ manual.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So instead, is it better to implement the error function for unexpected arguments manually?
Like the below for the beginning of the function.
extra_args <- setdiff(names(list(...)), names(formals(as_forecast.default)))
if (length(extra_args) > 0) {
stop(paste("Unknown argument(s):", paste(extra_args, collapse = ", ")))
}
# Curent implementation.
I am also happy with as it is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Since additional arguments just have no effect at all, I would personally not throw an error for this. Given that the ...
are there I would not expect an error as a user if I provide an additional argument.
This comment was marked as resolved.
This comment was marked as resolved.
I just pushed a new commit that updates the documentation a bit. Open questions (either before merging this PR or for a new PR):
|
I agree on making it easy for the user here though good to have a back and forth on the different options. I like the idea of allowing people to manually specify the type as a safety check. I think either default arg option is fine so happy to leave as is |
Perfect. I made the following updates:
Also note that compared to the very first proposal, I changed the order of the arguments, which now is
It felt more natural that way as |
Unsure where the failing snapshots on |
Update: given that |
This snapshot failure is due to the recent |
Are we happy to merge as is (bypassing branch protection)? |
393cc54
to
23b708e
Compare
Description
This PR closes #585
As discussed in #585 it is convenient for users to be able to specify the forecast unit, as well as changes to column names they need to make as part of
as_forecast()
.This PR
observed
,predicted
,model
,forecast_unit
,quantile_level
,sample_id
toas_forecast()
that allow the users to specify the desired forecast unit as well as desired changes to column namesas_forecast()
Additional thoughts and considerations:
forecast_unit
to be the first argument. Strong opinions? At the moment I put it there because I felt it was more natural to first specify the columns to be renamed and then the forecast unit and then the special columns. But 🤷sample_id
andquantile_level
to those methods. As mentioned in Discussion: Letas_forecast
explicitly specify column names from user inputted data. #585 I feel this would lead to unnecessary complexity (having to callas_forecast()
-->as_forecast.default()
-->as_forecast()
-->as_forecast.forecast_sample()
just to hide an argument that is clearly explained in the docs).Checklist
lintr::lint_package()
to check for style issues introduced by my changes.