Skip to content

NA handling bug in testing a_j = a_c #11

Description

@davidorme

Hi,

This line introduces a problem with NA values:

https://github.com/stineb/rpmodel/blob/master/R/rpmodel.R#L437

In the presence of NAs (but no other problems) the test fails:

> any(c(FALSE, NA))  # returns NA
[1] NA
> if(any(c(FALSE, NA))) { stop('a_j!=a_c')}  # if() statement chokes,
Error in if (any(c(FALSE, NA))) { : missing value where TRUE/FALSE needed

With grid maps as inputs, NAs are pretty likely and are handled by all steps up to this one. One alternative here is all.equal, which handles NAs and allows a tolerance to be set:

> all.equal(c(1,2,3,4, NA), c(1,2,3,4.001, NA), tol=0.001)
[1] TRUE
> all.equal(c(1,2,3,4, NA), c(NA, 2,3,4.001, NA), tol=0.001)
[1] "'is.NA' value mismatch: 2 in current 1 in target"

It would probably be useful to handle $a_j != a_c$ and mismatched NA values separately though? So trap the output of that all.equal and report separately or perhaps use a separate xor(is.na(a_j), is.na(a_c))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions