Skip to content

Commit

Permalink
Patch for construct_model() (#147)
Browse files Browse the repository at this point in the history
**Reference GitHub issue associated with pull request.** _e.g., 'closes
#<issue number>'_
Related #146


--------------------------------------------------------------------------------

Pre-review Checklist (if item does not apply, mark is as complete)
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] PR branch has pulled the most recent updates from master branch:
`usethis::pr_merge_main()`
- [ ] If a bug was fixed, a unit test was added.
- [ ] If a new `ard_*()` function was added, it passes the ARD
structural checks from `cards::check_ard_structure()`.
- [ ] If a new `ard_*()` function was added, `set_cli_abort_call()` has
been set.
- [ ] If a new `ard_*()` function was added and it depends on another
package (such as, `broom`), `is_pkg_installed("broom", reference_pkg =
"cardx")` has been set in the function call and the following added to
the roxygen comments: `@examplesIf
do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"",
reference_pkg = "cardx"))`
- [ ] Code coverage is suitable for any new functions/features
(generally, 100% coverage for new code): `devtools::test_coverage()`

Reviewer Checklist (if item does not apply, mark is as complete)

- [ ] If a bug was fixed, a unit test was added.
- [ ] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the
heading "`# cardx (development version)`". If there is an issue
associated with the pull request, reference it in parentheses at the end
update (see `NEWS.md` for examples).
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
  • Loading branch information
ddsjoberg authored May 6, 2024
1 parent 24dd32e commit 1a9c7ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 5 additions & 1 deletion R/construction_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ construct_model.survey.design <- function(x, formula, method, method.args = list
}

.as_list_of_exprs <- function(x) {
call_args(enexpr(x))
x_enexpr <- enexpr(x)
if (tryCatch(inherits(x, "list"), error = \(x) FALSE)) {
return(x)
}
call_args(x_enexpr)
}

#' @rdname construction_helpers
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-ard_stats_anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ test_that("ard_stats_anova.data.frame() works", {
}
ard_anova_geeglm2 <- args_fun(list(id = cyl))
expect_equal(
ard_anova_geeglm2,
ard_anova_geeglm
ard_anova_geeglm2$stat,
ard_anova_geeglm$stat
)
})

Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-construction_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ test_that("construct_model() works", {
"cannot be namespaced"
)

expect_equal(
{
outside_fun <- function() {
method.args <- list()

construct_model.data.frame(
mtcars,
formula = mpg ~ cyl,
method = "lm",
method.args = method.args
) |>
coef()
}

outside_fun()
},
lm(mpg ~ cyl, mtcars) |> coef()
)

# now the survey method -------
# styler: off
expect_equal({
Expand Down

0 comments on commit 1a9c7ee

Please sign in to comment.