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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add data types doc * add listsxp nextto pairlist * fix: add `data-types.qmd` to the mix * additional types written --------- Co-authored-by: Mossa <[email protected]>
- Loading branch information
1 parent
9544462
commit 12f9e29
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: R to Rust type mapping | ||
--- | ||
|
||
extendr is allows us to create a bridge between R and Rust. When writing a function in Rust that is intended to be called from R, it is important that the input types be R types. There are many types of objects in R (almost) all of which are available in extendr via a wrapper struct. | ||
|
||
The below lists the extendr structs that wrap R object types. These types can be used as function arguments or return values. | ||
|
||
## Scalar types | ||
|
||
| R type | extendr type | Rust type | | ||
| ------| -----------| ----------| | ||
| `integer(1)` | `Rint` | `i32` | | ||
| `double(1)` | `Rfloat` | `f64` | | ||
| `logical(1)` | `Rbool` | `bool` | | ||
| `complex(1)` | `Rcplx` | `Complex<f64>` | | ||
| `character(1)` | `Rstr` | `String` | | ||
|
||
## Vector types | ||
|
||
| R type | extendr type | extendr scalar type | C API Type | | ||
|-------------|------------|-------------------|----------| | ||
| `integer()` | `Integers` | `Rint` | `INTSXP` | | ||
| `double()` | `Doubles` | `Rfloat` | `REALSXP` | | ||
| `logical()` | `Logicals` | `Rbool` | `LGLSXP` | | ||
| `complex()` | `Complexes` | `Rcplx` | `CPLXSXP` | | ||
| `character()` | `Strings` | `Rstr` | `STRSXP` | | ||
| `raw()` | `Raw` | `&[u8]` | `RAWSXP` | | ||
| `list()` | `List` | `Robj` | `VECSXP` | | ||
|
||
|
||
## Other types | ||
|
||
|
||
- [`Environment`](https://extendr.github.io/extendr/extendr_api/wrapper/environment/struct.Environment.html) (`ENVSXP`) | ||
- [`Expressions`](https://extendr.github.io/extendr/extendr_api/wrapper/expr/struct.Expressions.html) (`EXPRSXP`) | ||
- [`ExternalPtr`](https://extendr.github.io/extendr/extendr_api/wrapper/externalptr/struct.ExternalPtr.html) (`EXTPTRSXP`) | ||
- [`Function`](https://extendr.github.io/extendr/extendr_api/wrapper/function/struct.Function.html) (`CLOSSXP`) | ||
- [`Language`](https://extendr.github.io/extendr/extendr_api/wrapper/lang/struct.Language.html) (`LANGSXP`) | ||
- [`RArray`](https://extendr.github.io/extendr/extendr_api/wrapper/matrix/struct.RArray.html) | ||
- [`Pairlist`](https://extendr.github.io/extendr/extendr_api/wrapper/pairlist/struct.Pairlist.html) (`LISTSXP`) | ||
- [`Promise`](https://extendr.github.io/extendr/extendr_api/wrapper/promise/struct.Promise.html) (`PROMSXP`) | ||
- [`S4`](https://extendr.github.io/extendr/extendr_api/wrapper/s4/struct.S4.html) (`S4SXP`) | ||
|
||
## Using Rust library types vs R-native types | ||
|
||
## Returning Rust values to R |