Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list0() needs to capture names #25

Closed
jmbarbone opened this issue May 11, 2023 · 0 comments · Fixed by #26
Closed

list0() needs to capture names #25

jmbarbone opened this issue May 11, 2023 · 0 comments · Fixed by #26
Assignees
Labels
bug Something isn't working

Comments

@jmbarbone
Copy link
Owner

list0 <- function (...) {
  mc <- match.call()
  out <- list()
  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)
      }
    })
  }
  
  # TODO include this line
  names(out) <- names(mc)[seq_len(i)][-1]
  out
}

fuj::list0(1, 2, 3,)
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> [[3]]
#> [1] 3
fuj::list0(a = 1, 2, c = 3,)
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> [[3]]
#> [1] 3
list0(1, 2, 3,)
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> [[3]]
#> [1] 3
list0(a = 1, 2, c = 3,)
#> $a
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> $c
#> [1] 3

Created on 2023-05-11 with reprex v2.0.2

@jmbarbone jmbarbone added the bug Something isn't working label May 11, 2023
@jmbarbone jmbarbone self-assigned this May 11, 2023
jmbarbone added a commit that referenced this issue May 15, 2023
jmbarbone added a commit that referenced this issue May 15, 2023
jmbarbone added a commit that referenced this issue May 15, 2023
jmbarbone added a commit that referenced this issue May 15, 2023
@jmbarbone jmbarbone mentioned this issue May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant