-
Notifications
You must be signed in to change notification settings - Fork 111
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
Error in vctrs::list_unchop()
in some instances when using recode inside of step_mutate()
#1083
Comments
Hello @jjcurtin Thank you so much for the bug report! I was able to reproduce it. It is happening in the print method, and is depended on the width of the output library(recipes)
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#>
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#>
#> step
library(modeldata)
ames_1 <- ames %>%
select(Sale_Price, MS_Zoning) %>%
mutate(MS_Zoning = as.character(MS_Zoning)) %>%
glimpse()
#> Rows: 2,930
#> Columns: 2
#> $ Sale_Price <int> 215000, 105000, 172000, 244000, 189900, 195500, 213500, 191…
#> $ MS_Zoning <chr> "Residential_Low_Density", "Residential_High_Density", "Res…
rec_ex2 <-
recipe(Sale_Price ~ ., data = ames_1) %>%
step_mutate(MS_Zoning = dplyr::recode(.x = MS_Zoning,
Residential_Low_Density = "r_ld",
Residential_Medium_Density = "r_md"))
options(width = 100)
rec_ex2
#> Recipe
#>
#> Inputs:
#>
#> role #variables
#> outcome 1
#> predictor 1
#>
#> Operations:
#>
#> Variable mutation for dplyr::recode(.x = MS_Zoning, Residential_Low_Density = "r_ld"...
options(width = 60)
rec_ex2
#> Recipe
#>
#> Inputs:
#>
#> role #variables
#> outcome 1
#> predictor 1
#>
#> Operations:
#>
#> Variable mutation for
#> Error in `vctrs::list_unchop()`:
#> ! Can't merge the outer name `MS_Zoning` with a vector of length > 1.
#> Please supply a `.name_spec` specification.
#> Backtrace:
#> ▆
#> 1. ├─base::tryCatch(...)
#> 2. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 3. │ ├─base (local) tryCatchOne(...)
#> 4. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 5. │ └─base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
#> 6. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 7. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 8. ├─base::withCallingHandlers(...)
#> 9. ├─base::saveRDS(...)
#> 10. ├─base::do.call(...)
#> 11. ├─base (local) `<fn>`(...)
#> 12. ├─global `<fn>`(input = base::quote("cheap-stoat_reprex.R"))
#> 13. │ └─rmarkdown::render(input, quiet = TRUE, envir = globalenv(), encoding = "UTF-8")
#> 14. │ └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
#> 15. │ └─knitr:::process_file(text, output)
#> 16. │ ├─base::withCallingHandlers(...)
#> 17. │ ├─knitr:::process_group(group)
#> 18. │ └─knitr:::process_group.block(group)
#> 19. │ └─knitr:::call_block(x)
#> 20. │ └─knitr:::block_exec(params)
#> 21. │ └─knitr:::eng_r(options)
#> 22. │ ├─knitr:::in_input_dir(...)
#> 23. │ │ └─knitr:::in_dir(input_dir(), expr)
#> 24. │ └─knitr (local) evaluate(...)
#> 25. │ └─evaluate::evaluate(...)
#> 26. │ └─evaluate:::evaluate_call(...)
#> 27. │ ├─evaluate (local) handle(...)
#> 28. │ │ └─base::try(f, silent = TRUE)
#> 29. │ │ └─base::tryCatch(...)
#> 30. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 31. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 32. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 33. │ ├─base::withCallingHandlers(...)
#> 34. │ ├─base::withVisible(value_fun(ev$value, ev$visible))
#> 35. │ └─knitr (local) value_fun(ev$value, ev$visible)
#> 36. │ └─knitr (local) fun(x, options = options)
#> 37. │ ├─base::withVisible(knit_print(x, ...))
#> 38. │ ├─knitr::knit_print(x, ...)
#> 39. │ └─knitr:::knit_print.default(x, ...)
#> 40. │ └─evaluate (local) normal_print(x)
#> 41. │ ├─base::print(x)
#> 42. │ └─recipes:::print.recipe(x)
#> 43. │ ├─base::print(x$steps[[i]], form_width = form_width)
#> 44. │ └─recipes:::print.step_mutate(x$steps[[i]], form_width = form_width)
#> 45. │ └─recipes::print_step(x$inputs, x$inputs, x$trained, title, width)
#> 46. │ └─recipes::format_selectors(untr_obj, width = width)
#> 47. │ └─vctrs::list_unchop(x_items, ptype = character())
#> 48. └─rlang::abort(message = message) Created on 2023-02-07 with reprex v2.0.2 |
Hi Emil,
Thanks for the update. I suspected it was something about the print method but I hadn't considered console width. I just confirmed that I can affect the error just by stretching or shrinking the width of my console in RStudio (I have it in the right pane). I can probably adjust the web book for my course for now using the width option. Will there be an easy fix for the print method?
Thanks for the help.
John
John J. Curtin, Ph.D.
Professor of Psychology,
Director of Clinical Training, and
Scientist - Center for Health Enhancement Systems Studies
Department of Psychology
University of Wisconsin-Madison
1202 West Johnson St
Madison, WI 53706
608-262-0387
https://arc.psych.wisc.edu<https://arc.psych.wisc.edu/>
pronouns: he/him/his
…________________________________
From: Emil Hvitfeldt ***@***.***>
Sent: Tuesday, February 7, 2023 1:07 PM
To: tidymodels/recipes ***@***.***>
Cc: John J. Curtin ***@***.***>; Mention ***@***.***>
Subject: Re: [tidymodels/recipes] Error in `vctrs::list_unchop()` in some instances when using recode inside of step_mutate() (Issue #1083)
Hello @jjcurtin<https://github.com/jjcurtin> Thank you so much for the bug report! I was able to reproduce it. It is happening in the print method, and is depended on the width of the output
library(recipes)
#> Loading required package: dplyr
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
#>
#> Attaching package: 'recipes'
#> The following object is masked from 'package:stats':
#>
#> step
library(modeldata)
ames_1 <- ames %>%
select(Sale_Price, MS_Zoning) %>%
mutate(MS_Zoning = as.character(MS_Zoning)) %>%
glimpse()
#> Rows: 2,930
#> Columns: 2
#> $ Sale_Price <int> 215000, 105000, 172000, 244000, 189900, 195500, 213500, 191…
#> $ MS_Zoning <chr> "Residential_Low_Density", "Residential_High_Density", "Res…
rec_ex2 <-
recipe(Sale_Price ~ ., data = ames_1) %>%
step_mutate(MS_Zoning = dplyr::recode(.x = MS_Zoning,
Residential_Low_Density = "r_ld",
Residential_Medium_Density = "r_md"))
options(width = 100)
rec_ex2
#> Recipe
#>
#> Inputs:
#>
#> role #variables
#> outcome 1
#> predictor 1
#>
#> Operations:
#>
#> Variable mutation for dplyr::recode(.x = MS_Zoning, Residential_Low_Density = "r_ld"...
options(width = 60)
rec_ex2
#> Recipe
#>
#> Inputs:
#>
#> role #variables
#> outcome 1
#> predictor 1
#>
#> Operations:
#>
#> Variable mutation for
#> Error in `vctrs::list_unchop()`:
#> ! Can't merge the outer name `MS_Zoning` with a vector of length > 1.
#> Please supply a `.name_spec` specification.
#> Backtrace:
#> ▆
#> 1. ├─base::tryCatch(...)
#> 2. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 3. │ ├─base (local) tryCatchOne(...)
#> 4. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 5. │ └─base (local) tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
#> 6. │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 7. │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 8. ├─base::withCallingHandlers(...)
#> 9. ├─base::saveRDS(...)
#> 10. ├─base::do.call(...)
#> 11. ├─base (local) `<fn>`(...)
#> 12. ├─global `<fn>`(input = base::quote("cheap-stoat_reprex.R"))
#> 13. │ └─rmarkdown::render(input, quiet = TRUE, envir = globalenv(), encoding = "UTF-8")
#> 14. │ └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
#> 15. │ └─knitr:::process_file(text, output)
#> 16. │ ├─base::withCallingHandlers(...)
#> 17. │ ├─knitr:::process_group(group)
#> 18. │ └─knitr:::process_group.block(group)
#> 19. │ └─knitr:::call_block(x)
#> 20. │ └─knitr:::block_exec(params)
#> 21. │ └─knitr:::eng_r(options)
#> 22. │ ├─knitr:::in_input_dir(...)
#> 23. │ │ └─knitr:::in_dir(input_dir(), expr)
#> 24. │ └─knitr (local) evaluate(...)
#> 25. │ └─evaluate::evaluate(...)
#> 26. │ └─evaluate:::evaluate_call(...)
#> 27. │ ├─evaluate (local) handle(...)
#> 28. │ │ └─base::try(f, silent = TRUE)
#> 29. │ │ └─base::tryCatch(...)
#> 30. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 31. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 32. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 33. │ ├─base::withCallingHandlers(...)
#> 34. │ ├─base::withVisible(value_fun(ev$value, ev$visible))
#> 35. │ └─knitr (local) value_fun(ev$value, ev$visible)
#> 36. │ └─knitr (local) fun(x, options = options)
#> 37. │ ├─base::withVisible(knit_print(x, ...))
#> 38. │ ├─knitr::knit_print(x, ...)
#> 39. │ └─knitr:::knit_print.default(x, ...)
#> 40. │ └─evaluate (local) normal_print(x)
#> 41. │ ├─base::print(x)
#> 42. │ └─recipes:::print.recipe(x)
#> 43. │ ├─base::print(x$steps[[i]], form_width = form_width)
#> 44. │ └─recipes:::print.step_mutate(x$steps[[i]], form_width = form_width)
#> 45. │ └─recipes::print_step(x$inputs, x$inputs, x$trained, title, width)
#> 46. │ └─recipes::format_selectors(untr_obj, width = width)
#> 47. │ └─vctrs::list_unchop(x_items, ptype = character())
#> 48. └─rlang::abort(message = message)
Created on 2023-02-07 with reprex v2.0.2<https://reprex.tidyverse.org>
—
Reply to this email directly, view it on GitHub<#1083 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFKEGFAI2HGCH2QSDEWTUBLWWKMPXANCNFSM6AAAAAAUTRJKJ4>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I have a fix in #1084. If you want to continue working right away you can run |
Big thanks for such a quick fix. I installed the branched version, and it solved the problem. My students and I are much appreciative!
John
John J. Curtin, Ph.D.
Professor of Psychology,
Director of Clinical Training, and
Scientist - Center for Health Enhancement Systems Studies
Department of Psychology
University of Wisconsin-Madison
1202 West Johnson St
Madison, WI 53706
608-262-0387
https://arc.psych.wisc.edu<https://arc.psych.wisc.edu/>
pronouns: he/him/his
…________________________________
From: Emil Hvitfeldt ***@***.***>
Sent: Tuesday, February 7, 2023 2:11 PM
To: tidymodels/recipes ***@***.***>
Cc: John J. Curtin ***@***.***>; Mention ***@***.***>
Subject: Re: [tidymodels/recipes] Error in `vctrs::list_unchop()` in some instances when using recode inside of step_mutate() (Issue #1083)
I have a fix in #1084<#1084>. If you want to continue working right away you can run remotes::install_github("tidymodels/recipes#1084") to install that specific branch. Once it is merged you can use remotes::install_github("tidymodels/recipes") to get the Dev branch.
—
Reply to this email directly, view it on GitHub<#1083 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFKEGFETHVGQ4HR3MTNFMODWWKT7NANCNFSM6AAAAAAUTRJKJ4>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
This issue 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. |
The problem
I'm having trouble with the use of
dplyr::recode()
inside ofstep_mutate()
from the recipes package. I am trying to recode text in a character variable. In some instances, these recodes work fine. But in other instances, it produces an error (Error invctrs::list_unchop()
). I provide a number of examples below of when it works and when it produces an error. My apologies if there is something fundamentally wrong with my code but I can't detect what that could be.Reproducible example
Created on 2023-02-06 with reprex v2.0.2
Session info
The text was updated successfully, but these errors were encountered: