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
(ENVSXP
)Expressions
(EXPRSXP
)ExternalPtr
(EXTPTRSXP
)Function
(CLOSSXP
)Language
(LANGSXP
)RArray
Pairlist
(LISTSXP
)Promise
(PROMSXP
)S4
(S4SXP
)