Skip to content

Commit

Permalink
extendr-macros: Using extendr_api import
Browse files Browse the repository at this point in the history
  • Loading branch information
CGMossa committed Feb 12, 2024
1 parent 125907c commit 7fad560
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions extendr-macros/src/R.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn R(item: TokenStream, expand_params: bool) -> TokenStream {
Err(_) => {
// If not a string, expand the tokens to make a string.
let src = format!("{}", item);
return quote!(eval_string(#src));
return quote!(extendr_api::eval_string(#src));
}
};

Expand Down Expand Up @@ -39,12 +39,12 @@ pub fn R(item: TokenStream, expand_params: bool) -> TokenStream {
}

if expressions.is_empty() {
quote!(eval_string(#src))
quote!(extendr_api::eval_string(#src))
} else {
quote!(
{
let params = &[#expressions];
eval_string_with_params(#src, params)
extendr_api::eval_string_with_params(#src, params)
}
)
}
Expand All @@ -61,13 +61,13 @@ mod test {
// Naked R!
assert_eq!(
format!("{}", R(quote!(data.frame), true)),
format!("{}", quote!(eval_string("data . frame")))
format!("{}", quote!(extendr_api::eval_string("data . frame")))
);

// Quoted R!
assert_eq!(
format!("{}", R(quote!("data.frame"), true)),
format!("{}", quote!(eval_string("data.frame")))
format!("{}", quote!(extendr_api::eval_string("data.frame")))
);

// Param R!
Expand All @@ -77,21 +77,21 @@ mod test {
"{}",
quote!({
let params = &[&extendr_api::Robj::from(1)];
eval_string_with_params("a <- param.0 ", params)
extendr_api::eval_string_with_params("a <- param.0 ", params)
})
)
);

// Unquoted R!
assert_eq!(
format!("{}", R(quote!(r#""hello""#), true)),
format!("{}", quote!(eval_string("\"hello\"")))
format!("{}", quote!(extendr_api::eval_string("\"hello\"")))
);

// Rraw!
assert_eq!(
format!("{}", R(quote!("a <- {{1}}"), false)),
format!("{}", quote!(eval_string("a <- {{1}}")))
format!("{}", quote!(extendr_api::eval_string("a <- {{1}}")))
);
}
}

0 comments on commit 7fad560

Please sign in to comment.