View source: R/params_resolve_missing.R
resolve_missing | R Documentation |
Uses relationships between parameters to iteratively fill in missing values. It is possible to specify an inconsistent set of rules or data in which case the resulting values will be picked up and an error thrown.
resolve_missing(
...,
.env = rlang::caller_env(),
.eval_null = TRUE,
.error = NULL
)
... |
either a set of relationships as a list of |
.env |
the environment to check in (optional - defaults to |
.eval_null |
The default behaviour (when this option is |
.error |
a glue specification defining the error message. This can use
parameters |
nothing. Alters the .env
environment to fill in missing values or
throws an informative error
# missing variables left with no default value in function definition
testfn = function(pos, neg, n) {
resolve_missing(pos=n-neg, neg=n-pos, n=pos+neg)
return(tibble::tibble(pos=pos,neg=neg,n=n))
}
testfn(pos=1:4, neg = 4:1)
testfn(neg=1:4, n = 10:7)
try(testfn())
# not enough info to infer the missing variables
try(testfn(neg=1:4))
# the parameters given are inconsistent with the relationships defined.
try(testfn(pos=2, neg=1, n=4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.