Skip to content

Add 'enforce_lapply' or similar to fparse/fload #64

@tdeenes

Description

@tdeenes

It is a great feature of the package that one does not need to call lapply() on character vectors since fparse\fload are already vectorized. However, this also means that the output type depends on whether the input contains a single element or multiple elements, e.g.:

inp2 <- as.character(1:2)
RcppSimdJson::fparse(inp2)
# [[1]]
# [1] 1
# 
# [[2]]
# [1] 2

inp1 <- as.character(1)
RcppSimdJson::fparse(inp1)
# [1] 1

So to be on the safe side, one has to check if the input vector is of length 1, and if yes, one has to wrap the result in a list. E.g.:

safe_fparse <- function(json, ...) {
  out <- RcppSimdJson::fparse(json, ...)
  if (length(json) == 1L) out <- list(out)
  out
}
safe_fparse("1")
# [[1]]
# [1] 1

What about adding an argument to fparse/fload which enforces that each element of the input json is wrapped in a list?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions