From 43983bb7a4b2705b2d62cf1b7ec1ffffe2cc4325 Mon Sep 17 00:00:00 2001 From: CGMossa Date: Wed, 15 May 2024 21:23:25 +0200 Subject: [PATCH] Remove `use-try-from` (#354) * removed `use_try_from`, and added `use_rng` * otherwise, this does not work * typo * Updated `NEWS.md` --- NEWS.md | 1 + R/function_options.R | 2 +- R/license_note.R | 2 +- README.Rmd | 1 - README.md | 1 - tests/data/ndarray_example.rs | 2 +- tests/testthat/test-extendr_function_options.R | 8 ++++---- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index b5c7b6dc..a935f940 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/function_options.R b/R/function_options.R index 83fd444d..c5d7c0c1 100644 --- a/R/function_options.R +++ b/R/function_options.R @@ -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() ) ) diff --git a/R/license_note.R b/R/license_note.R index 783b2d6c..d3c19b00 100644 --- a/R/license_note.R +++ b/R/license_note.R @@ -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. diff --git a/README.Rmd b/README.Rmd index 95a3d9cb..56be3c57 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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 diff --git a/README.md b/README.md index 85e16249..1168815b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tests/data/ndarray_example.rs b/tests/data/ndarray_example.rs index 64f68dce..6fe82a71 100644 --- a/tests/data/ndarray_example.rs +++ b/tests/data/ndarray_example.rs @@ -1,6 +1,6 @@ use extendr_api::prelude::*; -#[extendr(use_try_from = true)] +#[extendr] fn matrix_sum(input : ArrayView2) -> Rfloat { input.iter().sum() } diff --git a/tests/testthat/test-extendr_function_options.R b/tests/testthat/test-extendr_function_options.R index 09161830..c00cc20b 100644 --- a/tests/testthat/test-extendr_function_options.R +++ b/tests/testthat/test-extendr_function_options.R @@ -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( @@ -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) @@ -35,7 +35,7 @@ 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", { @@ -43,7 +43,7 @@ test_that("`rust_source()` errors if `extendr_fn_options` contains value of the # 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", {