Skip to main content

named_list_to_map

Function named_list_to_map 

Source
fn named_list_to_map<V, M, F>(sexp: SEXP, create_map: F) -> Result<M, SexpError>
where V: TryFromSexp, V::Error: Into<SexpError>, M: Extend<(String, V)>, F: FnOnce(usize) -> M,
Expand description

Helper to convert R named list to a map type.

Returns an error if the list has duplicate non-empty, non-NA names.

ยงNA and Empty Name Handling

Warning: Elements with NA or empty names are converted with key "":

  • NA names become empty string key ""
  • Empty string names "" stay as ""
  • If multiple elements have NA/empty names, later ones silently overwrite earlier ones

This means data loss can occur without error if your list has multiple unnamed or NA-named elements.

Example of silent data loss:

# In R:
x <- list(a = 1, 2, 3)  # Elements 2 and 3 have empty names
# After conversion, only one of them survives under key ""

If you need all elements regardless of names, use Vec<(String, V)> instead, or convert the list to a vector first.