Skip to content

Commit

Permalink
Remove use-try-from (#354)
Browse files Browse the repository at this point in the history
* removed `use_try_from`, and added `use_rng`

* otherwise, this does not work

* typo

* Updated `NEWS.md`
  • Loading branch information
CGMossa authored May 15, 2024
1 parent 6156085 commit 43983bb
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Fixes an issue in pre-defined set of known features: added `either` (#338)
* `create_extendr_package()` allows user to create project directory using RStudio's **Project Command**. (#321)
* Support `RTOOLS44` (#347)
* Removed `use_try_from` as an option in `rust_function`, and added `use_rng` (#354)

# rextend 0.3.1

Expand Down
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
2 changes: 1 addition & 1 deletion R/license_note.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Generate LICENSE.note file.
#'
#' LICENSE.note generated by this function contains information about Rust crate dependencies.
#' To use this function, the [cargo-lincense](https://crates.io/crates/cargo-license) command must be installed.
#' To use this function, the [cargo-license](https://crates.io/crates/cargo-license) command must be installed.
#' @param force Logical indicating whether to regenerate LICENSE.note if LICENSE.note already exists.
#' @inheritParams register_extendr
#' @return No return value, called for side effects.
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
8 changes: 4 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,8 +8,8 @@ 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",
use_dev_extendr = TRUE
)

int_sum <- type_aware_sum(1:5)
Expand All @@ -35,15 +35,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 43983bb

Please sign in to comment.