Skip to content

Commit

Permalink
added "valid, but empty input" test, fix, refs carriedaymont#49
Browse files Browse the repository at this point in the history
  • Loading branch information
dchud committed Jun 10, 2021
1 parent e8e0724 commit 02a92c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
36 changes: 20 additions & 16 deletions R/growth.R
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ cleangrowth <- function(subjid,

# adult: send to cleanadult to do most of the work ----

if (!quietly){
cat(sprintf("[%s] Begin processing adult data...\n", Sys.time()))
}

# no need to do this if there's no data
if (nrow(data.adult) > 0){
if (!quietly){
cat(sprintf("[%s] Begin processing adult data...\n", Sys.time()))
}

# TODO: MAKE THIS BETTER -- FUNCTION OR SOMETHING
# TODO: BATCH LOGS??
# if parallel processing is desired, load additional modules
Expand Down Expand Up @@ -659,19 +659,23 @@ cleangrowth <- function(subjid,
}


# join with pediatric data
full_out <- data.table(
line = c(ret.df$line, res$line),
exclude = c(as.character(ret.df$exclude), res$result),
mean_sde = c(rep(NA, nrow(ret.df)), res$mean_sde)
)
full_out[, exclude := factor(exclude, levels = unique(c(exclude.levels,
unique(exclude))))]
full_out <- full_out[order(line),]
# remove column added for keeping track
full_out[, line := NULL]
if (any(nrow(data.all) > 0, nrow(data.adult) > 0)) {
# join with pediatric data
full_out <- data.table(
line = c(ret.df$line, res$line),
exclude = c(as.character(ret.df$exclude), res$result),
mean_sde = c(rep(NA, nrow(ret.df)), res$mean_sde)
)
full_out[, exclude := factor(exclude, levels = unique(c(exclude.levels,
unique(exclude))))]
full_out <- full_out[order(line),]
# remove column added for keeping track
full_out[, line := NULL]

return(full_out$exclude)
return(full_out$exclude)
} else {
return(c())
}

}

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-cleangrowth.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ test_that("growthcleanr works without either adult or pediatric data", {
# using default cutpoint -- 20
only_peds <- syngrowth[syngrowth$agedays < 20*365.25,][1:50,]
only_adult <- syngrowth[syngrowth$agedays >= 20*365.25,][1:50,]
nobody <- syngrowth[syngrowth$agedays > 120*365.25,]

# testing cleangrowth works without adult data
peds_res <- cleangrowth(
Expand All @@ -119,4 +120,15 @@ test_that("growthcleanr works without either adult or pediatric data", {

expect_equal(length(adult_res), nrow(only_adult))

# testing cleangrowth works with no data
no_res <- cleangrowth(
nobody$subjid,
nobody$param,
nobody$agedays,
nobody$sex,
nobody$measurement,
quietly = T
)

expect_equal(length(no_res), nrow(nobody))
})

0 comments on commit 02a92c3

Please sign in to comment.