-
-
Notifications
You must be signed in to change notification settings - Fork 873
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
Add Rust Engine #1823
Add Rust Engine #1823
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! It'll be great if you could use <-
or =
consistently (personally I prefer the latter). Thank you!
|
FWIW I just saw there is a rust knitr engine in the R package extender https://github.com/extendr/rextendr Not yet on CRAN but part of a rust for R ecosystem. A good home for such an engine. |
Feedback is welcome! R Markdown-related usages can be found here: |
The extendr package looks much more promising than calling the command directly via |
Adding support for running Rust code in
```{rust}
and```{cargo}
chunks.```{rust}
chunks callrustc
, while```{cargo}
chunks callcargo run
. The main difference is that,```{cargo}
chunks allow using external crates, but this also comes at a cost of additional configuration (see below).```{rust}
implementation details:This is achieved by copying code into a temporary file
foo.rs
and then runrustc foo.rs && ./foo
.You may need to specify the path to
rustc
in~/.Renviron
becauseSys.getenv('PATH')
in R is different fromecho $PATH
in shell.Demo:
You can even omit
fn main()
in simple cases:(this is achieved by first
grep
ping 'fn main', and if it's not found, wrapping your code withfn main(){
and}
```{cargo}
implementation details:options(knitr.cargo.path= "PATH_TO_CARGO")
, wherePATH_TO_CARGO
is the directory that containsCargo.toml
Please suggest a better name forknitr.cargo.path
!eng_rust_cargo()
extracts the cargo directory usinggetOption("knitr.cargo.path")
```{cargo}
block is copied toCARGO_DIR/src/main.rs
(fn main() {}
added if absent)setwd()
to the cargo directory, andcargo run -q
is executed bysystem2()
, then wd is resetDemo: