extendr / rextendr

An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically
https://extendr.github.io/rextendr/
Other
181 stars 27 forks source link

Improve methods documentation when using `extendr` with `impl` #256

Closed daniellga closed 1 year ago

daniellga commented 1 year ago

For the following example, it seems only the docs for MySubmoduleClass are generated. Would it be possible to autogenerate also the docs for each method? I think it would be very nice, if doable, to be able to call ?MySubmoduleClass$new or ?MySubmoduleClass$set_a on the R side.

// Class for testing
#[derive(Default, Debug)]
struct MySubmoduleClass {
    a: i32,
}

/// Class for testing (exported)
/// @examples
/// x <- MySubmoduleClass$new()
/// x$a()
/// x$set_a(10)
/// x$a()
/// @export
#[extendr]
impl MySubmoduleClass {
    /// Method for making a new object.
    fn new() -> Self {
        Self { a: 0 }
    }

    /// Method for setting stuff.
    /// @param x a number
    fn set_a(& mut self, x: i32) {
        self.a = x;
    }

    /// Method for getting stuff.
    fn a(&self) -> i32 {
        self.a
    }

    /// Method for getting one's self.
    fn me(&self) -> &Self {
        self
    }
}
Ilia-Kosenkov commented 1 year ago

It seems this is a limitation of R. I think this should be closed.

JosiahParry commented 1 year ago

Indeed a limitation. See related issues commented or mentioned in https://github.com/r-lib/roxygen2/issues/835