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

How to handle NSE arguments in construct_model(method.args) ? #146

Closed
ddsjoberg opened this issue May 6, 2024 · 3 comments · Fixed by #184
Closed

How to handle NSE arguments in construct_model(method.args) ? #146

ddsjoberg opened this issue May 6, 2024 · 3 comments · Fixed by #184

Comments

@ddsjoberg
Copy link
Collaborator

I was working with a situation illustrated below that resulted in an error.

outside_fun <- function() {
  method.args <- list()
  
  construct_model.data.frame(
    mtcars, 
    formula = mpg ~ cyl,
    method = "lm", 
    method.args = method.args, 
    package = package
  )
}

outside_fun()

The original function that handles the potential NSE nature of method.args looked like this:

.as_list_of_exprs <- function(x) {
  call_args(enexpr(x))
}

I've added a small patch to this function, but it is not really how these things should be handled. I am not sure why the previous code was not working.

ddsjoberg added a commit that referenced this issue May 6, 2024
**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".
@ddsjoberg ddsjoberg added this to the v0.2.0 Release milestone Jun 19, 2024
@ddsjoberg
Copy link
Collaborator Author

We would like to remove this tryCatch and still have everything work.

construct_helpers.R

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

@ddsjoberg
Copy link
Collaborator Author

We can also add a check on the expression before we try to parse it. is_call_simple(x, ns = NULL) to have better error messaging

@thisisnic
Copy link
Contributor

This was fixed by #179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants