Skip to contents

There is currently one global option:

  • tidypolars_unknown_args controls what happens when some arguments passed in an expression are unknown, e.g the argument prob in sample(). The default ("warn") only warns the user that some arguments are ignored by tidypolars. The only other accepted value is "error" to throw an error when this happens.

Examples

options(tidypolars_unknown_args = "warn")
test <- polars::pl$DataFrame(x = c(2, 1, 5, 3, 1))

# The default is to warn the user
mutate(test, x2 = sample(x, prob = 0.5))
#> Warning: 
#> Package tidypolars doesn't know how to use some arguments of `sample()`.
#> The following argument(s) will be ignored: `prob`.
#> shape: (5, 2)
#> ┌─────┬─────┐
#> │ x   ┆ x2  │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═════╪═════╡
#> │ 2.0 ┆ 3.0 │
#> │ 1.0 ┆ 1.0 │
#> │ 5.0 ┆ 5.0 │
#> │ 3.0 ┆ 2.0 │
#> │ 1.0 ┆ 1.0 │
#> └─────┴─────┘

# But one can make this stricter and throw an error when this happens
options(tidypolars_unknown_args = "error")
try(mutate(test, x2 = sample(x, prob = 0.5)))
#> Error in mutate(test, x2 = sample(x, prob = 0.5)) : 
#>   Error while running function `sample()` in Polars.
#>  Package tidypolars doesn't know how to use some arguments of `sample()`: `prob`.
#>  Use `options(tidypolars_unknown_args = "warn")` to warn when this happens instead of throwing an error.

options(tidypolars_unknown_args = "warn")