-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Description
Get currently calls GetAttribute with its default nullAsNa = TRUE. This leads to problems when the user is trying to Prune or otherwise traverse the tree using is.na().
data.tree/R/node_methods_traversal.R
Line 190 in 24bd7da
| function(x) GetAttribute(x, |
Reprex:
> library(data.tree)
> data(acme)
> acme$Get("cost")
Acme Inc. Accounting New Software
NA NA 1000000
New Accounting Standards Research New Product Line
500000 NA 2000000
New Labs IT Outsource
750000 NA 400000
Go agile Switch to R
250000 50000
> Prune(acme, function(node) is.na(node$cost))
Error in if (!pruneFun(node$children[[i]])) { :
argument is of length zero
> #This will work
>Prune(acme, function(node) is.null(node$cost))
[1] 7
Understandably, setting nullAsNa = FALSE returns a list instead of a vector,
> class(acme$Get("cost", nullAsNa=FALSE))
[1] "list"
> class(acme$Get("cost", nullAsNa=TRUE))
[1] "numeric"
Still, should this print a warning or be documented somewhere to avoid confusion?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels