purrr
purrr copied to clipboard
Could map_dbl return empty vector for empty elements (revival)?
Hi,
This is a revival of #337:
Use
.default = NA
Originally posted by @hadley in https://github.com/tidyverse/purrr/issues/337#issuecomment-311067457
In fact, applying the closing comment does not solve the original question:
unlist(lapply(list(1), function(x) x[-1]))
#> numeric(0)
purrr::map_dbl(list(1), ~ .x[-1])
#> Error: Result 1 must be a single double, not a double vector of length 0
purrr::map_dbl(list(1), ~ .x[-1], .default=-99)
#> Error: Result 1 must be a single double, not a double vector of length 0
Created on 2021-10-23 by the reprex package (v2.0.1)
It seems that .default
is working when the result is NULL
but not if the result is of length 0.
It would be very convenient if this were the case.