Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow model piping for models within a multi-target #22

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add failing test (it will likely be modified later)
  • Loading branch information
billdenney committed Mar 19, 2024
commit de3675e5950ca02f2c3fd37e63272ef83124abb5
47 changes: 47 additions & 0 deletions tests/testthat/test-tar_nlmixr_multimodel.R
Original file line number Diff line number Diff line change
@@ -169,3 +169,50 @@ targets::tar_test("tar_nlmixr_multimodel works with initial condition setting `c
# to the `central(0) <- 0` line
expect_type(targets::tar_outdated(callr_function = NULL), "character")
})

test_that("tar_nlmixr_multimodel works for within-list model piping (#19)", {
pheno <- function() {
ini({
lcl <- log(0.008); label("Typical value of clearance")
lvc <- log(0.6); label("Typical value of volume of distribution")
etalcl + etalvc ~ c(1,
0.01, 1)
cpaddSd <- 0.1; label("residual variability")
})
model({
cl <- exp(lcl + etalcl)
vc <- exp(lvc + etalvc)
kel <- cl/vc
d/dt(central) <- -kel*central
cp <- central/vc
cp ~ add(cpaddSd)
})
}

target_list <-
tar_nlmixr_multimodel(
name = foo, data = nlmixr2data::pheno_sd, est = "saem",
"my first model" = pheno,
"my second model" = foo[["my first model"]] |> rxode2::ini(lcl = log(0.01))
)
expect_true(inherits(target_list, "list"))
# One for each model and then one for combining everything
expect_length(target_list, 3)
# Data and object simplification, then the fitting
expect_length(target_list[[1]], 4)
# Data and object simplification, then the fitting
expect_length(target_list[[2]], 4)
# Combine the fit models as a single step
expect_s3_class(target_list[[3]], "tar_stem")
expect_equal(target_list[[3]]$settings$name, "foo")

# Verify the expression for collation is generated correctly
collating_call <- target_list[[3]]$command$expr[[1]]
expect_true(grepl(x = as.character(collating_call[[2]]), pattern = "^foo_[0-9a-f]{8}$"))
expect_true(grepl(x = as.character(collating_call[[3]]), pattern = "^foo_[0-9a-f]{8}$"))
expect_equal(names(collating_call), c("", "my first model", "my second model"))

# Verify the targets created are the ones being collated
expect_equal(collating_call[[2]], as.name(target_list[[1]][[4]]$settings$name))
expect_equal(collating_call[[3]], as.name(target_list[[2]][[4]]$settings$name))
})