extendr: Handling of missing values
Do we have a systematic way of handling NA
values on the Rust side? It’s not clear to me what the current intent is to handling missing values. Most basic Rust data types (e.g., String
) cannot handle missing values. Instead, Rust uses options. Maybe we should systematically wrap all incoming data types into options?
As an example, the current implementation silently converts NA_character_
into "NA"
, which I would argue is incorrect behavior.
library(rextendr)
rust_function(
code = "fn rust_strings(input: &str) -> String {
input.to_string()
}",
patch.crates_io = c(
'extendr-api = { git = "https://github.com/extendr/extendr" }',
'extendr-macros = { git = "https://github.com/extendr/extendr" }'
)
)
rust_strings("a")
#> [1] "a"
rust_strings(NA_character_)
#> [1] "NA"
Created on 2020-12-05 by the reprex package (v0.3.0)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 25 (25 by maintainers)
To summarise:
from_robj()
forOption<i32>
and `Option<f64> for inputs.Robj::from()
forOption<i32>
andOption<f64>
for outputs.As a wider note, we may want iterators to do the same. maybe
str_iter_opt()
numeric_iter_opt()
integer_iter_opt()
to give an optional iterators.Likewise,
collect_robj()
should take options.