Skip to content

Commit

Permalink
Merge pull request #182 from iNZightVIT/release/1.12.1
Browse files Browse the repository at this point in the history
Release 1.12.1
  • Loading branch information
tmelliott authored Nov 4, 2021
2 parents d7a3b70 + 4117a73 commit 9ba8e26
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: iNZightTools
Type: Package
Title: Tools for 'iNZight'
Version: 1.12.0
Version: 1.12.1
Depends: R (>= 4.0)
Imports:
chron,
Expand Down
5 changes: 5 additions & 0 deletions NEWS.Md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## iNZightTools 1.12.1

- fix bug in `smart_read()` where parsing column types (numerc -> categorical) failed if `NA`s in column
- fix test failing in new version of survey (2.4)

# iNZightTools 1.12.0

- add new support for metadata formats:
Expand Down
5 changes: 4 additions & 1 deletion R/import_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ validate_type_changes <- function(x, column_types) {
"c" = {
## Convert numeric to factor
ncol <- suppressWarnings(as.numeric(as.character(col)))
if (any(is.na(ncol)) || !all(ncol == col))
# skip if ONE missing (not both)
colm <- ncol == col | (is.na(col) + is.na(ncol)) == 2L
colm <- ifelse(is.na(colm), FALSE, colm)
if (!all(colm))
return("")
lvls <- sort(unique(ncol))
if (is.factor(col)) {
Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/cas500-missing.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cellsource,rightfoot,travel,getlunch,height,gender,age,year,armspan,cellcost
pocket,20,walk,home,152,2,12,7,150,30
parent,25,other,friend,153,1,11,6,152,50
parent,21,motor,home,137,2,10,6,132,55
pocket,20,walk,home,115,2,9,5,130,60
pocket,23,other,home,165,1,14,10,160,20
parent,19,motor,home,137,,11,7,50,50
parent,23,motor,home,164,1,12,8,164,10
pocket,35,motor,tuckshop,150,1,15,11,100,20
parent,22,motor,home,150,,12,8,152,10
other,30,walk,tuckshop,123,2,14,9,23,0
parent,30,motor,tuckshop,185,2,14,9,180,60
parent,23,other,home,162,1,13,9,157,20
job,13,bus,home,180,1,14,9,165,20
parent,22,bus,home,164,1,15,10,127,26
job,24,train,home,153,,10,6,158,55
parent,28,motor,home,176,2,14,9,178,20
parent,11,bike,home,129,2,10,5,165,0
other,23,motor,home,145,2,10,6,144,25
parent,40,motor,tuckshop,160,2,14,9,160,60
pocket,25,bus,home,155,,13,8,150,10
parent,28,motor,home,155,2,12,8,155,0
parent,19,motor,home,146,1,9,4,140,25
job,29,walk,none,165,,13,9,164,50
4 changes: 2 additions & 2 deletions tests/testthat/test_aggregateData.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ test_that("Aggregating survey data is valid", {
skip("Old version of srvyr")
}

qf <- survey::svyquantile
skip_if(packageVersion("survey") < package_version('4.2'))
expect_equal(
svy_agg$api99_q25,
svyby(~api99, ~stype, svy, survey::svyquantile,
quantiles = 0.25, keep.var = FALSE)[1, c(2, 6, 10)] %>% as.double()
quantiles = 0.25, keep.var = FALSE, ci = FALSE)$statistic
)
expect_equal(eval(parse(text = code(svy_agg))), svy_agg, ignore_attr = TRUE)
})
9 changes: 9 additions & 0 deletions tests/testthat/test_smart_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ test_that("Column type overrides are respected", {

# null should also work
expect_s3_class(smart_read("cas500.csv", column_types = NULL), "data.frame")

# NA values in num to cat conversion is OK
cas_missing <- smart_read("cas500-missing.csv", column_types = c(gender = "c"))
expect_s3_class(cas_missing$gender, "factor")
expect_equal(
eval(parse(text = paste(code(cas_missing), collapse = "\n"))),
cas_missing,
ignore_attr = TRUE
)
})

test_that("SAS Import num to cat works", {
Expand Down

0 comments on commit 9ba8e26

Please sign in to comment.