-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot use extendrsrc
with a macro that contains #[extendr]
#350
Comments
It could also be that it does not understand macros (which is definitely on another level). |
Its worth noting that it does compile the macro iff |
Ok I get it. The issue here is two-fold. We generate exports based on simple scanning for
|
Looking at this, now I believe it could be related to function name starting with |
It's not a 'bug', it's a 'feature'. We cannot parse deep into things like macros (since we do simple pattern search and not AST traversal), but your issue can be bypassed. You can disable export module generation and do exports yourself: sample.Rmd---
title: "Test Macros"
output: markdown_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(rextendr)
```
```{extendrsrc macro, engine.opts = list(generate_module_macro = FALSE)}
macro_rules! make_heck_fn {
($fn_name:ident) => {
#[extendr]
/// @export
fn $fn_name(x: Strings) -> Strings {
x.into_iter()
.map(|xi| match xi.is_na() {
true => Rstr::na(),
false => Rstr::from(xi.as_str().$fn_name()),
})
.collect::<Strings>()
}
};
}
trait SomeTrait {
fn some_fn(&self) -> String;
}
impl SomeTrait for &str {
fn some_fn(&self) -> String {
format!("'{}' is a hecking string!", self)
}
}
make_heck_fn!(some_fn);
extendr_module!{
mod rextendr;
fn some_fn;
}
```
```{r}
some_fn(c("a", "b", NA))
```
knits into sample.md---
title: "Test Macros"
output: markdown_document
---
``` rust
macro_rules! make_heck_fn {
($fn_name:ident) => {
#[extendr]
/// @export
fn $fn_name(x: Strings) -> Strings {
x.into_iter()
.map(|xi| match xi.is_na() {
true => Rstr::na(),
false => Rstr::from(xi.as_str().$fn_name()),
})
.collect::<Strings>()
}
};
}
trait SomeTrait {
fn some_fn(&self) -> String;
}
impl SomeTrait for &str {
fn some_fn(&self) -> String {
format!("'{}' is a hecking string!", self)
}
}
make_heck_fn!(some_fn);
extendr_module!{
mod rextendr;
fn some_fn;
}
```
``` r
some_fn(c("a", "b", NA))
```
```
## [1] "'a' is a hecking string!" "'b' is a hecking string!"
## [3] NA
```
|
The text was updated successfully, but these errors were encountered: