Skip to content

Commit

Permalink
Sourcing the exported extendr_wrappers.R (extendr#7)
Browse files Browse the repository at this point in the history
* Sourcing the exported extendr_wrappers.R

This makes use of extendr#40.

* Added a test

This test needs to be reworked for every setup..

* Removed wrapper function code.

Co-authored-by: hobofan <[email protected]>

* Skipping machine specific test

Co-authored-by: hobofan <[email protected]>
  • Loading branch information
2 people authored and Ilia-Kosenkov committed Jan 14, 2021
1 parent 671dfd8 commit 617c1e9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 62 deletions.
56 changes: 0 additions & 56 deletions R/exported_functions.R

This file was deleted.

5 changes: 1 addition & 4 deletions R/source.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ rust_source <- function(file, code = NULL, dependencies = NULL,


# generate R bindings for shared library
funs <- get_exported_functions(rust_file) # extract function declarations
r_functions <- generate_r_functions(funs)
r_path <- file.path(dir, "R", "rextendr.R")
brio::write_lines(r_functions, r_path)
r_path <- file.path(dir, "target", "extendr_wrappers.R")
source(r_path, local = env)

# load shared library
Expand Down
49 changes: 47 additions & 2 deletions tests/testthat/test-source.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
# implementation of actual tests will require updated extendr-api, extendr-macros, libR-sys
# on crates.io.

test_that("multiplication works", {
expect_equal(2 * 2, 4)
test_that("Testing the source", {
skip("This would typically fail, unless changed to reflect paths /
on host's machine. ")
# some simple Rust code with two functions
rust_src <- "use extendr_api::*;
#[extendr]
fn hello() -> &'static str {
\"Hello, this string was created by Rust.\"
}
#[extendr]
fn add_and_multiply(a: i32, b: i32, c: i32) -> i32 {
c * (a + b)
}
#[extendr]
fn add(a: i64, b: i64) -> i64 {
a + b
}
#[extendr]
fn say_nothing() {
}
"

rust_source(
code = rust_src,
# use `patch.crates_io` argument to override crate locations
patch.crates_io = c(
'extendr-api = {path = "C:/Users/tpb398/Documents/GitHub/extendR/extendr-api"}',
'extendr-macros = {path = "C:/Users/tpb398/Documents/GitHub/extendR/extendr-macros"}'
),
quiet = FALSE,
cache_build = TRUE
)

# call `hello()` function from R
hello()
#> [1] "Hello, this string was created by Rust."

# call `add()` function from R
expect_equal(add(14, 23), 37)
#> [1] 37
expect_equal(add(17, 42), 17 + 42)

})

0 comments on commit 617c1e9

Please sign in to comment.