Skip to content

Error when fitting workflow with step_dummy() #263

Description

@cphaarmeyer

The problem

I'm having trouble with fitting a model while using step_dummy().

Reproducible example

library(tidymodels)
library(tidyclust)
#> 
#> Attaching package: 'tidyclust'
#> The following objects are masked from 'package:parsnip':
#> 
#>     knit_engine_docs, list_md_problems

data <- tibble(x = factor(c("a", "b")))

spec <- k_means(num_clusters = 2)
rec <- recipe(~., data = data) |> step_dummy(x)
wf <- workflow(rec, spec)

fit(wf, data = data)
#> Error in `unique.default()`:
#> ! unique() applies only to vectors

Created on 2026-06-23 with reprex v2.1.1

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.5.3 (2026-03-11)
#>  os       Linux Mint 22.3
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language en_GB
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Berlin
#>  date     2026-06-23
#>  pandoc   3.8.3 @ /usr/share/positron/resources/app/quarto/bin/tools/x86_64/ (via rmarkdown)
#>  quarto   1.9.38 @ /usr/share/positron/resources/app/quarto/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version    date (UTC) lib source
#>  backports      1.5.1      2026-04-03 [1] RSPM
#>  broom        * 1.0.13     2026-05-14 [1] RSPM
#>  class          7.3-23     2025-01-01 [2] CRAN (R 4.5.3)
#>  cli            3.6.6      2026-04-09 [1] RSPM
#>  codetools      0.2-20     2024-03-31 [2] CRAN (R 4.5.3)
#>  data.table     1.18.4     2026-05-06 [1] RSPM
#>  dials        * 1.4.4      2026-06-22 [1] RSPM
#>  DiceDesign     1.10       2023-12-07 [1] RSPM
#>  digest         0.6.39     2025-11-19 [1] RSPM
#>  dplyr        * 1.2.1      2026-04-03 [1] RSPM
#>  evaluate       1.0.5      2025-08-27 [1] RSPM
#>  farver         2.1.2      2024-05-13 [1] RSPM
#>  fastmap        1.2.0      2024-05-15 [1] RSPM
#>  fs             2.1.0      2026-04-18 [1] RSPM
#>  furrr          0.4.0      2026-03-31 [1] RSPM
#>  future         1.70.0     2026-03-14 [1] RSPM
#>  future.apply   1.20.2     2026-02-20 [1] RSPM
#>  generics       0.1.4      2025-05-09 [1] RSPM
#>  ggplot2      * 4.0.3      2026-04-22 [1] CRAN (R 4.5.3)
#>  globals        0.19.1     2026-03-13 [1] RSPM
#>  glue           1.8.1      2026-04-17 [1] CRAN (R 4.5.3)
#>  gower          1.0.2      2024-12-17 [1] RSPM
#>  gtable         0.3.6      2024-10-25 [1] RSPM
#>  hardhat        1.4.3      2026-04-04 [1] RSPM
#>  htmltools      0.5.9      2025-12-04 [1] RSPM
#>  infer        * 1.1.0      2025-12-18 [1] CRAN (R 4.5.2)
#>  ipred          0.9-15     2024-07-18 [1] RSPM
#>  knitr          1.51       2025-12-20 [1] RSPM
#>  lattice        0.22-9     2026-02-09 [2] CRAN (R 4.5.3)
#>  lava           1.9.1      2026-05-14 [1] RSPM
#>  lifecycle      1.0.5      2026-01-08 [1] RSPM
#>  listenv        1.0.0      2026-06-22 [1] RSPM
#>  lubridate      1.9.5      2026-02-04 [1] CRAN (R 4.5.2)
#>  magrittr       2.0.5      2026-04-04 [1] RSPM
#>  MASS           7.3-65     2025-02-28 [2] CRAN (R 4.5.3)
#>  Matrix         1.7-4      2025-08-28 [2] CRAN (R 4.5.3)
#>  mclust         6.1.2      2025-10-31 [1] RSPM
#>  modeldata    * 1.5.1      2025-08-22 [1] RSPM
#>  modelenv       0.2.0      2024-10-14 [1] RSPM
#>  nnet           7.3-20     2025-01-01 [2] CRAN (R 4.5.3)
#>  otel           0.2.0      2025-08-29 [1] RSPM
#>  parallelly     1.47.0     2026-04-17 [1] CRAN (R 4.5.3)
#>  parsnip      * 1.6.0      2026-05-14 [1] RSPM
#>  pillar         1.11.1     2025-09-17 [1] RSPM
#>  pkgconfig      2.0.3      2019-09-22 [1] RSPM
#>  prodlim        2026.03.11 2026-03-11 [1] RSPM
#>  purrr        * 1.2.2      2026-04-10 [1] RSPM
#>  R6             2.6.1      2025-02-15 [1] RSPM
#>  RColorBrewer   1.1-3      2022-04-03 [1] RSPM
#>  Rcpp           1.1.1-1.1  2026-04-24 [1] RSPM
#>  recipes      * 1.3.3      2026-05-30 [1] RSPM
#>  reprex         2.1.1      2024-07-06 [1] RSPM
#>  rlang          1.2.0      2026-04-06 [1] RSPM
#>  rmarkdown      2.31       2026-03-26 [1] RSPM
#>  rpart          4.1.24     2025-01-07 [2] CRAN (R 4.5.3)
#>  rsample      * 1.3.2      2026-01-30 [1] RSPM
#>  S7             0.2.2      2026-04-22 [1] CRAN (R 4.5.3)
#>  scales       * 1.4.0      2025-04-24 [1] RSPM
#>  sessioninfo    1.2.4      2026-06-04 [1] RSPM
#>  sparsevctrs    0.3.6      2026-01-27 [1] RSPM
#>  survival       3.8-6      2026-01-16 [2] CRAN (R 4.5.3)
#>  tailor       * 0.1.0      2025-08-25 [1] RSPM
#>  tibble         3.3.1      2026-01-11 [1] RSPM
#>  tidyclust    * 0.3.1      2026-06-20 [1] RSPM
#>  tidymodels   * 1.5.0      2026-04-23 [1] CRAN (R 4.5.3)
#>  tidyr        * 1.3.2      2025-12-19 [1] CRAN (R 4.5.2)
#>  tidyselect     1.2.1      2024-03-11 [1] RSPM
#>  timechange     0.4.0      2026-01-29 [1] RSPM
#>  timeDate       4052.112   2026-01-28 [1] RSPM
#>  tune         * 2.1.0      2026-04-17 [1] RSPM
#>  vctrs          0.7.3      2026-04-11 [1] RSPM
#>  withr          3.0.3      2026-06-19 [1] RSPM
#>  workflows    * 1.3.0      2025-08-27 [1] RSPM
#>  workflowsets * 1.1.1      2025-05-27 [1] RSPM
#>  xfun           0.59       2026-06-19 [1] RSPM
#>  yaml           2.3.12     2025-12-10 [1] CRAN (R 4.5.2)
#>  yardstick    * 1.4.0      2026-04-07 [1] RSPM
#> 
#>  [1] /home/philipp/R/x86_64-pc-linux-gnu-library/4.5
#>  [2] /opt/R/4.5.3/lib/R/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Further investigation reveals that parsnip::maybe_matrix() converts the data to a sparse matrix and hence unique(data) throws an error. The conversion does not happen when calling maybe_matrix(tibble(x_b = 0:1)) directly for some reason.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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