Feature Request: Change default parameters to extract attributes of `.df`
averissimo opened this issue · comments
Feature Idea
Currently, the default parameters of metadata
, domain
(and in the future verbose
) are set with NULL
This implicitly means that it will default back to the data frame attributes (if they exist)
Proposal
We could change it to extract the respective attribute from .df
diff --git a/R/length.R b/R/length.R
index 05fadff..d760245 100644
--- a/R/length.R
+++ b/R/length.R
@@ -58,9 +58,9 @@
#'
#' adsl <- xportr_length(adsl, metadata, domain = "adsl")
xportr_length <- function(.df,
- metadata = NULL,
- domain = NULL,
- verbose = NULL,
+ metadata = attr(.df, "_xportr.df_metadata_"),
+ domain = attr(.df, "_xportr.df_arg_"),
+ verbose = attr(.df, "_xportr.df_verbose_") %||% getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_stop(
Benefits
- The default parameters become explicit
- As this is the behaviour of the code, it will default to the data frame attribute if the argument is
NULL
- As this is the behaviour of the code, it will default to the data frame attribute if the argument is
- Cleans up repetitive code in the body of the
xportr_*
functions
Cons
- Non-technical users might find the
attr
odd on the parameter documentation
Alternatives
- Use helper functions (
extract_metadata(.df)
,extract_domain(.df)
,extract_verbose(.df)
)- instead of
attr()
function
- instead of
- Keep as is
Extra
For verbose
parameter we could go the extra mile and also include the fallback to the global option
Relevant Input
No response
Relevant Output
No response
Reproducible Example/Pseudo Code
No response