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

Allow easy access to development version of `extendr` from `rust_source()` methods #250

Closed Ilia-Kosenkov closed 1 year ago

Ilia-Kosenkov commented 1 year ago

Since extendr releases are infrequent, there can be a situation when a desired feature is already available in dev version of extendr, but not on crates.io. Currently, when dynamically compiling rust code, this can be overcome by hijacking extendr_deps or patch.crates_io:

rust_function(
  "fn uses_either() -> either::Either<Rint, Rfloat> { either::Either::Left(Rint::default()) }", 
  features = "either",
  extendr_deps = list(git = "https://github.com/extendr/extendr)
)

I propose to provide a shortcut in a form of a boolean flag use_dev_extendr = FALSE, which selects extendr_deps (stored in options).

So the abovementioned code simplifies to just

rust_function(
  "fn uses_either() -> either::Either<Rint, Rfloat> { either::Either::Left(Rint::default()) }", 
  features = "either",
  use_dev_extendr = TRUE
)

I believe this is a dramatic simplification of the API, allowing curious people to explore extendr features right from their R terminal, without the need of a complex project setup.

Note that we will not reduce the flexibility & functionality of rust_source(), it will just get an additional parameter, which will impact compilation only if extendr_deps are NULL ( == not specified by the user). In advanced scenarios, the flag is ignored.

CGMossa commented 1 year ago

By persuasion, I think you should go for the use_dev_extendr option, and honestly that will be used by us so often, that we probably won't deprecate that syntax for a long, long time.

Ilia-Kosenkov commented 1 year ago

Just to clarify, by ' use_dev_extendr option' you mean the example that I show above or perhaps getOption('use_dev_extendr')? Because if it is the first one, then I totally agree -- I myself will be using it A LOT :-D