Skip to content
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

fixes string interpolation failure for splines #1381

Merged
merged 1 commit into from
Oct 18, 2024
Merged

Conversation

topepo
Copy link
Member

@topepo topepo commented Oct 18, 2024

Closes #1380

msg_test <- "Error in if (df < 0) { : missing value where TRUE/FALSE needed\n"
recipes:::spline_msg(msg_test)
#> Error in `recipes:::spline_msg()`:
#> ! Error in if (df < 0) { : missing value where TRUE/FALSE needed

Created on 2024-10-18 with reprex v2.1.1

@@ -46,6 +46,14 @@ spline2_create <- function(x, nm = "pred", .fn = "bSpline", df = 3, complete_set

spline_msg <- function(x) {
x <- as.character(x)
# Error messages can contain brackets (e.g. "Error in if (df < 0) { : missing value")
Copy link
Member Author

Choose a reason for hiding this comment

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

A lot of comments so that future me/us will get the logic

# to change the delimiters but will ignore them if they are doubled. So we
# change "{" to "{{" (and also for close). Simultaneous substitution via
# `pattern = "(\\{)|(\\})"` produces poor results so we do them one at a time.
x <- gsub("(\\{)", "\\1\\1", x)
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe this can be done in one shot?

Copy link
Member

Choose a reason for hiding this comment

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

I'm perfectly fine to do it one at a time. we are throwing an error when this code is run so speed isn't an issue

@@ -1,6 +1,6 @@
Package: recipes
Title: Preprocessing and Feature Engineering Steps for Modeling
Version: 1.1.0.9000
Copy link
Member Author

Choose a reason for hiding this comment

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

So that I can updates tests/skips in tune

@@ -46,6 +46,14 @@ spline2_create <- function(x, nm = "pred", .fn = "bSpline", df = 3, complete_set

spline_msg <- function(x) {
Copy link
Member Author

Choose a reason for hiding this comment

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

For next week: pass the upstream caller env to avoid "Caused by error in spline_msg():"

topepo added a commit to tidymodels/tune that referenced this pull request Oct 18, 2024
# to change the delimiters but will ignore them if they are doubled. So we
# change "{" to "{{" (and also for close). Simultaneous substitution via
# `pattern = "(\\{)|(\\})"` produces poor results so we do them one at a time.
x <- gsub("(\\{)", "\\1\\1", x)
Copy link
Member

Choose a reason for hiding this comment

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

I'm perfectly fine to do it one at a time. we are throwing an error when this code is run so speed isn't an issue

@EmilHvitfeldt
Copy link
Member

looking good!

@EmilHvitfeldt EmilHvitfeldt merged commit cfd1166 into main Oct 18, 2024
11 checks passed
@EmilHvitfeldt EmilHvitfeldt deleted the double-brackets branch October 18, 2024 15:08
topepo added a commit to tidymodels/tune that referenced this pull request Oct 23, 2024
topepo added a commit to tidymodels/tune that referenced this pull request Oct 23, 2024
* add type checking files

* remove newly unneeded checking functions

* snapshot updates from tidymodels/recipes#1381

* updates files

* basic replacements

* type checker replacements

* tidymodels/tailor#53

* Update R/checks.R

Co-authored-by: Simon P. Couch <[email protected]>

* add remote to get proper error messages

* typo

* update remotes?

* only test snapshots with more recent version of R *with* rankdeficient

---------

Co-authored-by: Simon P. Couch <[email protected]>
Copy link

github-actions bot commented Nov 2, 2024

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 Nov 2, 2024
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.

string interpolation failure for splines
2 participants