Skip to content

Commit

Permalink
Check for simple calls in construct_model() (#179)
Browse files Browse the repository at this point in the history
FYI @thisisnic


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

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 committed Jun 30, 2024
1 parent 95a8240 commit 358e76d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
14 changes: 12 additions & 2 deletions R/construction_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,22 @@ construct_model.survey.design <- function(data, formula, method, method.args = l
)
}

.as_list_of_exprs <- function(x) {
.as_list_of_exprs <- function(x, arg_name = "method.args") {
x_enexpr <- enexpr(x)
if (is_call_simple(x_enexpr)) {
return(call_args(x_enexpr))
}

if (tryCatch(inherits(x, "list"), error = \(x) FALSE)) {
return(x)
}
call_args(x_enexpr)

cli::cli_abort(
c("There was an error processing the {.arg {argname}} argument.",
i = "Expecting a simple call. See {.help rlang::is_call_simple} for details."
),
call = get_cli_abort_call()
)
}

#' @rdname construction_helpers
Expand Down

0 comments on commit 358e76d

Please sign in to comment.