Currently, tidypolars
has only one global option:
tidypolars_unknown_args
controls what happens when some arguments passed in an expression are unknown, e.g the argumentprob
insample()
. The default ("warn"
) only warns the user that some arguments are ignored bytidypolars
. The only other accepted value is"error"
to throw an error when this happens.
The package polars
also contains several global options that may be useful,
such as changing the default behavior when converting Int64 values to R:
https://pola-rs.github.io/r-polars/man/polars_options.html.
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 ┆ 5.0 │
#> │ 1.0 ┆ 3.0 │
#> │ 5.0 ┆ 1.0 │
#> │ 3.0 ┆ 1.0 │
#> │ 1.0 ┆ 2.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")