-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use extendr_api::prelude::*; | ||
|
||
use gtars::io::{read_tokens_from_gtok, write_tokens_to_gtok}; | ||
|
||
/// Write tokens to a gtok file | ||
/// @export | ||
/// @param filename A string representing the path to the gtok file. | ||
#[extendr(r_name = "write_tokens_to_gtok")] | ||
pub fn r_write_tokens_to_gtok(filename: String, tokens: Vec<i32>) { | ||
let tokens: Vec<u32> = tokens.into_iter().map(|t| t as u32).collect(); | ||
let _ = write_tokens_to_gtok(&filename, &tokens); | ||
} | ||
|
||
/// Write tokens to a gtok file | ||
/// @export | ||
/// @param filename A string representing the path to the gtok file. | ||
#[extendr(r_name = "read_tokens_from_gtok")] | ||
pub fn r_read_tokens_from_gtok(filename: String) -> Vec<i32> { | ||
read_tokens_from_gtok(&filename) | ||
.unwrap() | ||
.into_iter() | ||
.map(|gtok| gtok as i32) | ||
.collect() | ||
} | ||
|
||
extendr_module! { | ||
mod io; | ||
fn r_read_tokens_from_gtok; | ||
fn r_write_tokens_to_gtok; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,11 @@ | ||
use extendr_api::prelude::*; | ||
|
||
use gtars::io::{read_tokens_from_gtok, write_tokens_to_gtok}; | ||
|
||
/// Return string `"Hello world!"` to R. | ||
/// @export | ||
#[extendr] | ||
fn hello_world() -> &'static str { | ||
"Hello world!" | ||
} | ||
|
||
/// Write tokens to a gtok file | ||
/// @export | ||
/// @param filename A string representing the path to the gtok file. | ||
#[extendr(r_name = "write_tokens_to_gtok")] | ||
fn r_write_tokens_to_gtok(filename: String, tokens: Vec<i32>) { | ||
let tokens: Vec<u32> = tokens.into_iter().map(|t| t as u32).collect(); | ||
let _ = write_tokens_to_gtok(&filename, &tokens); | ||
} | ||
|
||
/// Write tokens to a gtok file | ||
/// @export | ||
/// @param filename A string representing the path to the gtok file. | ||
#[extendr(r_name = "read_tokens_from_gtok")] | ||
fn r_read_tokens_from_gtok(filename: String) -> Vec<i32> { | ||
read_tokens_from_gtok(&filename) | ||
.unwrap() | ||
.into_iter() | ||
.map(|gtok| gtok as i32) | ||
.collect() | ||
} | ||
pub mod io; | ||
|
||
// Macro to generate exports. | ||
// This ensures exported functions are registered with R. | ||
// See corresponding C code in `entrypoint.c`. | ||
extendr_module! { | ||
mod gtars; | ||
fn hello_world; | ||
fn r_write_tokens_to_gtok; | ||
fn r_read_tokens_from_gtok; | ||
use io; | ||
} |