Skip to content

Commit

Permalink
Fix make check issues
Browse files Browse the repository at this point in the history
  • Loading branch information
billdenney committed Mar 7, 2024
1 parent a8482c8 commit 658fcfd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 11 additions & 7 deletions R/tar_nlmixr_multimodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#' modelFunction`
#' @inheritParams nlmixr2est::nlmixr
#' @inheritParams targets::tar_target
#' @param envir The environment where models are defined (usually doesn't need
#' to be modified)
#' @return A list of targets for the model simplification, data simplification,
#' and model estimation.
#' @export
tar_nlmixr_multimodel <- function(name, ..., data, est, control = list(), table = nlmixr2est::tableControl()) {
tar_nlmixr_multimodel <- function(name, ..., data, est, control = list(), table = nlmixr2est::tableControl(), envir = parent.frame()) {
if (is.null(est)) {
stop("'est' must not be null")

Check warning on line 14 in R/tar_nlmixr_multimodel.R

View check run for this annotation

Codecov / codecov/patch

R/tar_nlmixr_multimodel.R#L14

Added line #L14 was not covered by tests
}
Expand All @@ -20,11 +22,12 @@ tar_nlmixr_multimodel <- function(name, ..., data, est, control = list(), table
table = substitute(table),
# This extracts the ... argument similarly to using `substitute()`. From
# https://stackoverflow.com/questions/55019441/deparse-substitute-with-three-dots-arguments
model_list = match.call(expand.dots = FALSE)$...
model_list = match.call(expand.dots = FALSE)$...,
envir = envir
)
}

tar_nlmixr_multimodel_parse <- function(name, data, est, control, table, model_list) {
tar_nlmixr_multimodel_parse <- function(name, data, est, control, table, model_list, envir) {
checkmate::assert_named(model_list, type = "unique")
ret_prep <-
lapply(
Expand All @@ -34,26 +37,27 @@ tar_nlmixr_multimodel_parse <- function(name, data, est, control, table, model_l
data = data,
est = est,
control = control,
table = table
table = table,
envir = envir
)
# Extract the targets to fit. This will be a list of lists. The inner list
# will have the three targets for fitting the model, and the outer list will
# be one element per model fit.
target_model_fitting <- lapply(X = unname(ret_prep), FUN = \(x) x[["target"]])
# Generate the combined list with names
combined_list <- lapply(X = ret_prep, FUN = \(x) as.name(x$name))
target_combined_list <- tar_target_raw(name = name, command = str2lang(deparse(combined_list)))
target_combined_list <- targets::tar_target_raw(name = name, command = str2lang(deparse(combined_list)))
# Return the models to fit and the list-combining target
append(
target_model_fitting,
target_combined_list
)
}

tar_nlmixr_multimodel_single <- function(object, name, data, est, control, table) {
tar_nlmixr_multimodel_single <- function(object, name, data, est, control, table, envir) {
# Hash the model itself without its description. Then, if the description
# changes, the model will not need to rerun.
hash_long <- digest::digest(eval(object))
hash_long <- digest::digest(eval(object, envir = envir))
hash <- substr(hash_long, 1, 8)
name_hash <- paste(name, hash, sep = "_")
tar_prep <-
Expand Down
6 changes: 5 additions & 1 deletion man/tar_nlmixr_multimodel.Rd

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

0 comments on commit 658fcfd

Please sign in to comment.