Skip to content

Commit

Permalink
Merge pull request #10 from nlmixr2/fix-9
Browse files Browse the repository at this point in the history
Ensure that covariate columns are found for fitted objects
  • Loading branch information
billdenney authored Feb 6, 2024
2 parents 008a9d7 + 3157b35 commit 7885407
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
^nlmixrtargets\.Rproj$
^\.Rproj\.user$
^LICENSE$
^LICENSE\.md$
^README\.Rmd$
^cran-comments\.md$
Expand Down
7 changes: 6 additions & 1 deletion R/simplify.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ nlmixr_data_simplify <- function(data, object, table = list()) {
paste0("'", nlmixr_names[mask_duplicated], "'", collapse = ", ")
)
}
cov_names <- nlmixr_data_simplify_cols(data, cols = object$all.covs, type = "covariate")
if (!is.null(object$ui)) {
covVec <- object$ui$all.covs
} else {
covVec <- object$all.covs
}
cov_names <- nlmixr_data_simplify_cols(data, cols = covVec, type = "covariate")
keep_names <- nlmixr_data_simplify_cols(data, cols = table$keep, type = "keep")
# Simplifying the nlmixr_names column names to always be lower case ensures
# that upper/lower case column name changes will not affect the need to rerun.
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-simplify.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,20 @@ test_that("nlmixr_object_simplify_zero_initial", {
new_model <- nlmixr_object_simplify_zero_initial(pheno)
expect_equal(body(new_model), body(pheno_0))
})

test_that("re-estimating a model works with covariates (#9)", {
bad_data_lower_case <- nlmixr2data::pheno_sd
bad_data_lower_case$id <- bad_data_lower_case$ID
fit_estimated <-
suppressMessages(
nlmixr2est::nlmixr(
object = model_simple,
data = nlmixr2data::pheno_sd,
est = "focei",
control = list(eval.max = 1)
)
)
expect_true(
"WT" %in% names(nlmixr_data_simplify(data = nlmixr2data::pheno_sd, object = fit_estimated))
)
})

0 comments on commit 7885407

Please sign in to comment.