Skip to content

use rlang::is_call_simple #746

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

Merged
merged 5 commits into from
Jun 11, 2022
Merged

use rlang::is_call_simple #746

merged 5 commits into from
Jun 11, 2022

Conversation

EmilHvitfeldt
Copy link
Member

This PR aims to close #745.

Before, what used to happen when a namespaced call came in, rlang::call_name(x) would return NULL and the if statement would break. This is happening because bar::foo is a complex name, see rlang::call_name().

library(parsnip)

glm_model_ns <- linear_reg() %>%
  set_engine("glm", family = stats::gaussian(tune("hello")))

glm_model_ns$eng_args
#> <list_of<quosure>>
#> 
#> $family
#> <quosure>
#> expr: ^stats::gaussian(tune("hello"))
#> env:  0x1177b49c8

parsnip:::find_tune_id(glm_model_ns$eng_args[[1]])
#> [1] "hello"

sg_call <- rlang::expr(stats::gaussian)

is.call(sg_call)
#> [1] TRUE

rlang::call_name(sg_call)
#> NULL

rlang::is_call_simple(sg_call)
#> [1] FALSE

This change doesn't break anything (that I found) by running extratests. It works even if tune() is namespaced

library(parsnip)

glm_model_ns <- linear_reg() %>%
  set_engine("glm", family = stats::gaussian(tune::tune("hello")))

parsnip:::find_tune_id(glm_model_ns$eng_args[[1]])
#> [1] "hello"

Created on 2022-06-03 by the reprex package (v2.0.1)

@EmilHvitfeldt EmilHvitfeldt marked this pull request as ready for review June 3, 2022 21:49
Copy link
Member

@DavisVaughan DavisVaughan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me after reading the call_name() docs. Seems smart to guard those calls with is_call_simple() if you need to require that the result is a single TRUE/FALSE, as we do here

@topepo topepo merged commit d879482 into main Jun 11, 2022
@topepo topepo deleted the fix-745 branch June 11, 2022 23:32
@github-actions
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

find_tune_id() errors if expression is namespaced
3 participants