Skip to content

subsetting of outcome when outcome has label #1061

Closed
@simonpcouch

Description

@simonpcouch

When I was trying to reproduce #1060, this was my first go at a minimal reprex. There's no error here (at least for this engine), but parsnip takes only the first observation (and I'm assuming it's recycled later on?)

library(parsnip)

fit_xy(
  linear_reg(),
  data.frame(x = 1:5),
  y = structure(2:6, label = "hi")
)
#> parsnip model object
#> 
#> 
#> Call:
#> stats::lm(formula = ..y ~ ., data = data)
#> 
#> Coefficients:
#> (Intercept)            x  
#>   2.000e+00    1.573e-16

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

Notice intercept is 2 and slope is basically zero. This is because the outcome is always 2:6[[1]]😬

Offending code:

parsnip/R/fit.R

Lines 270 to 276 in 8ccf1be

if (object$engine != "spark" & NCOL(y) == 1 & !(is.vector(y) | is.factor(y))) {
if (is.matrix(y)) {
y <- y[, 1]
} else {
y <- y[[1]]
}
}

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