Skip to content

Get prints Null as NA by default #128

@nzxwang

Description

@nzxwang

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().

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions