Skip to content

Commit

Permalink
Add support for dnr = NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
stefvanbuuren committed May 10, 2024
1 parent 601e112 commit 1f456eb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Imports:
chartbox (>= 1.11.0),
chartcatalog (>= 1.10.0),
curvematching (>= 0.14.0),
donorloader (>= 0.32.0),
donorloader (>= 0.37.1),
dplyr (>= 1.0.10),
grDevices,
grid,
Expand Down
43 changes: 28 additions & 15 deletions R/process_chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#' default (`NULL`) reads from `donorloader` package.
#' @param dnr A string with the name of the donor data
#' (currently available are `smocc`, `terneuzen`,
#' `lollypop` and `pops`)
#' `lollypop`, `pops`, `0-2`, `2-4` and `4-18`). The default (`NULL`)
#' sets the donor data according to `period[2]`.
#' @param period A vector of length 2 with left and right ages
#' (decimal age). If `length(period) == 0L`, then no curve
#' matching is done
Expand Down Expand Up @@ -63,10 +64,7 @@ process_chart <- function(target,
curve_interpolation = TRUE,
quiet = TRUE,
con = NULL,
dnr = c(
"0-2", "2-4", "4-18",
"smocc", "lollypop", "terneuzen", "pops"
),
dnr = NULL,
period = numeric(0),
nmatch = 0L,
user_model = 2L,
Expand All @@ -76,15 +74,8 @@ process_chart <- function(target,
show_realized = FALSE,
show_future = FALSE,
clip = TRUE) {
dnr <- match.arg(dnr)

# make the switch to the donordata solution per age group
dnr <- switch(dnr,
"0-2" = "smocc",
"2-4" = "lollypop",
"4-18" = "terneuzen",
dnr
)
# set the donor data dnr
dnr <- set_dnr(dnr, period)

# load growthchart, return early if there is a problem
g <- load_chart(chartcode)
Expand Down Expand Up @@ -122,7 +113,7 @@ process_chart <- function(target,
return(g)
}

if (!nmatch || !length(period)) {
if (!nmatch || !length(period) || is.null(dnr)) {
# no matches needed
matches <- vector("list", length(ynames))
names(matches) <- ynames
Expand Down Expand Up @@ -158,3 +149,25 @@ process_chart <- function(target,
clip = clip
)
}

set_dnr <- function(dnr, period) {
if (!is.null(dnr)) {
dnr <- switch(dnr,
"0-2" = "smocc",
"2-4" = "lollypop",
"4-18" = "terneuzen",
dnr
)
} else {
# use period[2] to set dnr
if (length(period) != 2L || !is.numeric(period)) {
dnr <- NULL
} else {
to <- period[2L]
dnr <- "terneuzen"
if (to <= 2) dnr <- "smocc"
if (2 < to && to <= 4) dnr <- "lollypop"
}
}
return(dnr)
}
1 change: 1 addition & 0 deletions R/set_curves.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set_curves <- function(g,
clip = TRUE) {
chartcode <- g$name
if (!nmatch) period <- numeric(0)
if (is.null(dnr)) matches <- NULL

# get target data
child <- persondata(target)
Expand Down
3 changes: 2 additions & 1 deletion man/find_matches.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/process_chart.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/set_curves.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f456eb

Please sign in to comment.