Skip to content

Commit

Permalink
removed use_try_from, and added use_rng
Browse files Browse the repository at this point in the history
  • Loading branch information
CGMossa committed May 13, 2024
1 parent 6156085 commit 737af7d
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion R/function_options.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extendr_function_config <- rlang::env(
known_options = tibble::tribble(
~Name, ~Ptype,
"use_try_from", logical(),
"r_name", character(),
"mod_name", character(),
"use_rng", logical()
)
)

Expand Down
1 change: 0 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ rust_function(
}",
use_dev_extendr = TRUE, # Use development version of extendr from GitHub
features = "either", # Enable support for Either crate
extendr_fn_options = list(use_try_from = TRUE) # Enable advanced type conversion
)
x <- 1:5
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ rust_function(
}",
use_dev_extendr = TRUE, # Use development version of extendr from GitHub
features = "either", # Enable support for Either crate
extendr_fn_options = list(use_try_from = TRUE) # Enable advanced type conversion
)

x <- 1:5
Expand Down
2 changes: 1 addition & 1 deletion tests/data/ndarray_example.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use extendr_api::prelude::*;

#[extendr(use_try_from = true)]
#[extendr]
fn matrix_sum(input : ArrayView2<Rfloat>) -> Rfloat {
input.iter().sum()
}
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-extendr_function_options.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("`extendr` code is compiled with `either` feature and `use_try_from` enabled", {
test_that("`extendr` code is compiled with `either` feature", {
skip_if_cargo_unavailable()

rust_function(
Expand All @@ -8,7 +8,6 @@ test_that("`extendr` code is compiled with `either` feature and `use_try_from` e
Either::Right(right) => Either::Right(right.iter().sum())
}
}",
extendr_fn_options = list("use_try_from" = TRUE),
features = "either",
)

Expand All @@ -35,15 +34,15 @@ test_that("`r_name` option renames R function", {
})

test_that("`rust_source()` errors if `extendr_fn_options` contains `NULL` value", {
expect_rextendr_error(rust_function("fn func() {}", extendr_fn_options = list("use_try_from" = NULL)))
expect_rextendr_error(rust_function("fn func() {}", extendr_fn_options = list("use_rng" = NULL)))
})

test_that("`rust_source()` errors if `extendr_fn_options` contains value of the wrong type", {
skip_if_cargo_unavailable()

# due to the use of purrr here, the error that is emitted is on of class `mutate_error`
# we cannot expect `rextendr_error` from this function.
expect_error(rust_function("fn func() {}", extendr_fn_options = list("use_try_from" = 42L)))
expect_error(rust_function("fn func() {}", extendr_fn_options = list("use_rng" = 42L)))
})

test_that("`rust_source()` errors if `extendr_fn_options` contains option with an invalid name", {
Expand Down

0 comments on commit 737af7d

Please sign in to comment.