11extendr_function_config <- rlang :: env(
2- known_options = tibble :: tribble(
3- ~ Name , ~ Ptype ,
4- " r_name" , character (),
5- " mod_name" , character (),
6- " use_rng" , logical ()
2+ known_options = data.frame (
3+ Name = c(" r_name" , " mod_name" , " use_rng" ),
4+ Ptype = I(list (
5+ character (),
6+ character (),
7+ logical ()
8+ ))
79 )
810)
911
@@ -14,7 +16,7 @@ extendr_function_config <- rlang::env(
1416# ' @noRd
1517convert_function_options <- function (options , suppress_warnings ) {
1618 if (rlang :: is_null(options ) || rlang :: is_empty(options )) {
17- return (tibble :: tibble (Name = character (), RustValue = character ()))
19+ return (data.frame (Name = character (), RustValue = character ()))
1820 }
1921
2022 if (! rlang :: is_list(options ) || ! rlang :: is_named(options )) {
@@ -24,25 +26,25 @@ convert_function_options <- function(options, suppress_warnings) {
2426 )
2527 }
2628
27- options_table <- tibble :: tibble (Name = rlang :: names2(options ), Value = unname(options )) % > %
28- dplyr :: left_join(extendr_function_config $ known_options , by = " Name" ) % > %
29+ options_table <- data.frame (Name = rlang :: names2(options ), Value = I( unname(options ))) | >
30+ dplyr :: left_join(extendr_function_config $ known_options , by = " Name" ) | >
2931 dplyr :: mutate(
3032 Value = pmap(
3133 list (.data $ Value , .data $ Ptype , .data $ Name ),
32- ~ if (rlang :: is_null(..2 )) ..1 else vctrs :: vec_cast(..1 , ..2 , x_arg = ..3 )
34+ \( ... ) if (rlang :: is_null(..2 )) ..1 else vctrs :: vec_cast(..1 , ..2 , x_arg = ..3 )
3335 ),
3436 )
3537
36- unknown_option_names <- options_table % > %
37- dplyr :: filter(map_lgl(.data $ Ptype , rlang :: is_null )) % > %
38+ unknown_option_names <- options_table | >
39+ dplyr :: filter(map_lgl(.data $ Ptype , rlang :: is_null )) | >
3840 dplyr :: pull(.data $ Name )
3941
40- invalid_options <- options_table % > %
42+ invalid_options <- options_table | >
4143 dplyr :: mutate(
4244 IsNameInvalid = ! is_valid_rust_name(.data $ Name ),
4345 IsValueNull = map_lgl(.data $ Value , rlang :: is_null ),
4446 IsNotScalar = ! .data $ IsValueNull & ! map_lgl(.data $ Value , vctrs :: vec_is , size = 1L )
45- ) % > %
47+ ) | >
4648 dplyr :: filter(
4749 .data $ IsNameInvalid | .data $ IsValueNull | .data $ IsNotScalar
4850 )
@@ -56,7 +58,7 @@ convert_function_options <- function(options, suppress_warnings) {
5658 ))
5759 }
5860
59- options_table % > %
61+ options_table | >
6062 dplyr :: transmute(
6163 .data $ Name ,
6264 RustValue = map_chr(.data $ Value , convert_option_to_rust )
@@ -70,18 +72,18 @@ convert_function_options <- function(options, suppress_warnings) {
7072cli_abort_invalid_options <- function (invalid_options ) {
7173 n_invalid_opts <- vctrs :: vec_size(invalid_options ) # nolint: object_usage_linter
7274
73- invalid_names <- invalid_options % > % get_option_names(.data $ IsNameInvalid )
74- null_values <- invalid_options % > % get_option_names(.data $ IsValueNull )
75- vector_values <- invalid_options % > % get_option_names(.data $ IsNotScalar )
75+ invalid_names <- invalid_options | > get_option_names(.data $ IsNameInvalid )
76+ null_values <- invalid_options | > get_option_names(.data $ IsValueNull )
77+ vector_values <- invalid_options | > get_option_names(.data $ IsNotScalar )
7678
7779 message <- c(
7880 " Found {.val {n_invalid_opts}} invalid {.code extendr} function option{?s}:" ,
79- x = " Unsupported name{?s}: {.val {invalid_names}}." % > % if_any_opts(invalid_names ),
80- x = " Null value{?s}: {.val {null_values}}." % > % if_any_opts(null_values ),
81- x = " Vector value{?s}: {.val {vector_values}}." % > % if_any_opts(vector_values ),
82- i = " Option names should be valid rust names." % > % if_any_opts(invalid_names ),
83- i = " {.code NULL} values are disallowed." % > % if_any_opts(null_values ),
84- i = " Only scalars are allowed as option values." % > % if_any_opts(vector_values )
81+ x = " Unsupported name{?s}: {.val {invalid_names}}." | > if_any_opts(invalid_names ),
82+ x = " Null value{?s}: {.val {null_values}}." | > if_any_opts(null_values ),
83+ x = " Vector value{?s}: {.val {vector_values}}." | > if_any_opts(vector_values ),
84+ i = " Option names should be valid rust names." | > if_any_opts(invalid_names ),
85+ i = " {.code NULL} values are disallowed." | > if_any_opts(null_values ),
86+ i = " Only scalars are allowed as option values." | > if_any_opts(vector_values )
8587 )
8688
8789 cli :: cli_abort(message , class = " rextendr_error" )
@@ -93,8 +95,8 @@ cli_abort_invalid_options <- function(invalid_options) {
9395# ' @return A character vector of option names.
9496# ' @noRd
9597get_option_names <- function (invalid_options , filter_column ) {
96- invalid_options % > %
97- dplyr :: filter({{ filter_column }}) % > %
98+ invalid_options | >
99+ dplyr :: filter({{ filter_column }}) | >
98100 dplyr :: pull(.data $ Name )
99101}
100102
0 commit comments