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

review uses of vapply and refactor where duplicated #377

Closed
njtierney opened this issue Apr 21, 2021 · 3 comments · Fixed by #658
Closed

review uses of vapply and refactor where duplicated #377

njtierney opened this issue Apr 21, 2021 · 3 comments · Fixed by #658
Assignees
Labels
later For after "up next" low hanging fruit Issue is simple to implement.
Milestone

Comments

@njtierney
Copy link
Collaborator

e.g.,

https://github.com/greta-dev/greta/blob/master/R/simulate.R#L65

target_node_names <- vapply(target_nodes,
    member,
    "unique_name",
    FUN.VALUE = character(1)
  )
  object_node_names <- vapply(object$dag$node_list,
    member,
    "unique_name",
    FUN.VALUE = character(1)
  )

and

https://github.com/greta-dev/greta/blob/master/R/utils.R#L504

can be replaced with the new base::lengths

@njtierney njtierney self-assigned this Apr 21, 2021
@njtierney
Copy link
Collaborator Author

In vapply, FUN.VALUE is sometimes “” and other times, character(1), is there a difference/benefit from doing this?

@goldingn
Copy link
Member

Same result, but I think I switched to character(1) as it makes the intent clearer

@njtierney njtierney added later For after "up next" and removed Up Next labels Jun 17, 2021
@njtierney njtierney added the 0.5.0 label Jul 2, 2021
@njtierney njtierney modified the milestones: 0.4.0, 0.5.0 Jul 2, 2021
@njtierney njtierney removed the 0.5.0 label Jul 2, 2021
@njtierney njtierney modified the milestones: 0.5.0, 0.4.1 Jul 2, 2021
@njtierney njtierney added the low hanging fruit Issue is simple to implement. label Jul 27, 2024
@njtierney njtierney modified the milestones: 0.6.0, 0.5.0 Jul 27, 2024
@njtierney
Copy link
Collaborator Author

njtierney commented Jul 30, 2024

Some common vapply patterns:

  • vapply(x, member, "unique_name") (9)
  • vapply(x, identical, ...) (6)
  • vapply(x, is.null, ...) (5)
  • vapply(x, is.greta_array) (5)
  • vapply(x, has_distribution, ...) (4)
  • vapply(dot_nodes, is_scalar, logical(1)) (2)
  • vapply(x, member, "discrete") (2)
  • classes <- vapply(x, class, "") (1)
  • vapply(x, member, "multivariate") (1)
  • vapply(names, deparse, "")
  • vapply(nodes, dag$tf_name, ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
later For after "up next" low hanging fruit Issue is simple to implement.
Projects
Development

Successfully merging a pull request may close this issue.

2 participants