Skip to content

Commit

Permalink
simplify list0() (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbarbone committed Feb 20, 2024
1 parent f030c79 commit 1422fb3
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions R/list.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,16 @@
#' @examples
#' try(list(1, ))
#' list0(1, )
#' try(list(a = 1, ))
#' list0(a = 1, )
#' try(list(a = 1, , c = 3, ))
#' list0(a = 1, , c = 3, )
#' @export
list0 <- function(...) {
mc <- match.call()
out <- list()
off <- 0L

for (i in seq_len(...length())) {
tryCatch(
out <- append(out, ...elt(i)),
error = function(e) {
if (!identical(e$message, "argument is missing, with no default")) {
e$call <- mc
stop(e)
}

assign("off", 1L, parent.frame()$parentenv)
}
)
}

names(out) <- names(mc)[-1L][seq_len(i - off)]
out
e <- as.list(substitute(list(...)))[-1L]
do.call(list, e[e != substitute()], envir = parent.frame(2))
}

#' @export
#' @rdname list0
lst <- list0

0 comments on commit 1422fb3

Please sign in to comment.