Skip to content

Commit

Permalink
minor NMisNumeric bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
philipdelff committed Nov 16, 2022
1 parent 8c37365 commit 1d5904b
Show file tree
Hide file tree
Showing 9 changed files with 3,037 additions and 3,036 deletions.
23 changes: 2 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
MIT License

Copyright (c) 2019-2022 Philip Delff

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
YEAR: 2019-2022
COPYRIGHT HOLDER: Philip Delff
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@

* addTAPD was not respecting subset.dos for all generated columns.

* NMisNumeric would interpret a NA of class character or logical as
non-numeric. Fixed.

## Other improvements
* Internally, combination of input and output data without a row
identifier is simplified.
Expand Down
5 changes: 3 additions & 2 deletions R/NMisNumeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ NMisNumeric <- function(x,na.strings=".",each=FALSE){
inherits(x, "POSIXt") ||
inherits(x, "Date")
}

ok <- rep(TRUE,length(x))
if(is.logical(x) || is.timestamp(x)) {
ok[] <- FALSE
ok[!is.na(x)] <- FALSE
} else if(!is.numeric(x)){

ok[!is.na(x)&!as.character(x)%in%na.strings] <-
suppressWarnings(!is.na(as.numeric(as.character(x)[!is.na(x)&!as.character(x)%in%na.strings])))
}
Expand Down
4 changes: 1 addition & 3 deletions devel/todo.org
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,7 @@ The information is sufficient when taking into account the linesep
arguement. If length(lines) and linesep is given, a warning must be
issued. Once done, NMgetSection must be updated as well.
*** NMisNumeric
**** TODO [#A] NA_character is not recognized as numeric
NMisNumeric(c(NA)) is FALSE
NMisNumeric(NA_real_) is TRUE
**** DONE NA_character is not recognized as numeric
*** NMscanInput
**** DONE Test with multiple filters on the same column
like IGNORE(ID=2) IGNORE(ID=3)
Expand Down
3,006 changes: 1,503 additions & 1,503 deletions tests/testthat/testOutput/NMwriteData1.csv

Large diffs are not rendered by default.

3,006 changes: 1,503 additions & 1,503 deletions tests/testthat/testOutput/stampedData_8.csv

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tests/testthat/testOutput/stampedData_8_meta.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"parameter","value"
"DataCreateScript","A simple test"
"CreationTime","2021-11-21 11:00:00 EST"
"writtenTo","testOutput/stampedData_8.csv"
"parameter","value"
"DataCreateScript","A simple test"
"CreationTime","2021-11-21 11:00:00 EST"
"writtenTo","testOutput/stampedData_8.csv"
Binary file added tests/testthat/testReference/NMisNumeric_4.rds
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/testthat/test_NMisNumeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,21 @@ test_that("element-wise",{

expect_equal_to_reference(res,fileRef,version=2)
})


test_that("NA's",{
fileRef <- "testReference/NMisNumeric_4.rds"

dttest <- data.table(logic=NA
,char2=NA_character_
,num=NA_real_
,int=NA_integer_
)

res <- sapply(dttest,NMisNumeric)

res


expect_equal_to_reference(res,fileRef,version=2)
})

0 comments on commit 1d5904b

Please sign in to comment.