Skip to content

check_args() doesn't handle expression that well #1099

Open
@EmilHvitfeldt

Description

@EmilHvitfeldt

From

Any quoted arguments (such as the `family` example given above) are evaluated in this environment just before the model call is evaluated. For a user passes in an argument that is `floor(nrow(data)/3)`, this will be evaluated at this time in the captured environment.

In the following example if you jump into check_args(), it passes but for the wrong reasons.

check_args() doesn't eval in the environment. so floor(nrow(data)/3) becomes nuemric(0) because nrow(data) is NULL because data is a function...

Ideally we should handle it better. There might be reasons why we don't, but we should be sure. it also means that the checking right now needs to be looser than I would like, as checking "1 or 0" length isn't as good as checking "1" length.

library(parsnip)
library(discrim)

discrim_linear(penalty = floor(nrow(data)/3)) |>
  fit(Species ~ ., data = iris)
#> parsnip model object
#> 
#> Call:
#> lda(Species ~ ., data = data)
#> 
#> Prior probabilities of groups:
#>     setosa versicolor  virginica 
#>  0.3333333  0.3333333  0.3333333 
#> 
#> Group means:
#>            Sepal.Length Sepal.Width Petal.Length Petal.Width
#> setosa            5.006       3.428        1.462       0.246
#> versicolor        5.936       2.770        4.260       1.326
#> virginica         6.588       2.974        5.552       2.026
#> 
#> Coefficients of linear discriminants:
#>                     LD1         LD2
#> Sepal.Length  0.8293776 -0.02410215
#> Sepal.Width   1.5344731 -2.16452123
#> Petal.Length -2.2012117  0.93192121
#> Petal.Width  -2.8104603 -2.83918785
#> 
#> Proportion of trace:
#>    LD1    LD2 
#> 0.9912 0.0088

Created on 2024-04-02 with reprex v2.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions