This repository has been archived by the owner on Jun 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project-structure.qmd
52 lines (36 loc) · 1.59 KB
/
project-structure.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
title: extendr project structure
---
A extendr-powered R package has a fairly unique structure. This section briefly outlines the structure of an extendr package and the important files.
extendr works by creating a Rust library crate in `src/rust` that is defined by `src/rust/Cargo.toml`.
```{.toml filename="Cargo.toml"}
[package]
name = 'hellorust'
publish = false
version = '0.1.0'
edition = '2021'
[lib]
crate-type = [ 'staticlib' ]
name = 'hellorust'
[dependencies]
extendr-api = '*'
```
Note the `crate-type = [ 'staticlib' ]`. When this library is compiled, it creates a static library which can then be called from R.
## Controlling exports to R: `lib.rs`
The `lib.rs` file determines what will be exposed to your R package. The `extendr_module!` macro in `lib.rs` controls what will have wrappers provided to your R package.
```toml
extendr_module! {
mod hellorust;
fn hello_world;
}
```
The `mod hellorust` is the name of the R package. Additional functions, `impl`s, and modules can also be added to this macro.
## Building the package: `Makevars`
When creating an R package that uses compiled code, a file called `Makevars` is used.
::: callout-note
See [Using Makevars](https://cran.r-project.org/doc/manuals/R-exts.html#Using-Makevars) in Writing R Extensions for a thorough discussion.
:::
`Makevars` is used as a preprocessing step for compiling an R package. The files `Makevars` and `Makevars.win` compile the Rust library in `src/rust`, and link to the library.
::: callout-tip
`Makevars` is used for *nix operating systems and `Makevars.win` is used for Windows.
:::