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

finishing touches on columns yaml round trip #506

Merged
merged 6 commits into from
Nov 6, 2023

Conversation

yjunechoe
Copy link
Collaborator

A small patch in yaml read/write:

  • Writing columns is now c("a") instead of c(a) for extra clarity (since the latter can scope an env variable named a). More generally, the strict translation of vars(a) is c("a"), though users can get by with using the more familiar c(a) (and they still get the tidyselect deprecation warning if they accidentally scope an env var)
  • Reading is now aware of all tidyselect helpers, instead of just the handful that used to be supported. It now reads e.g., where(is.numeric) as-is, and not as "where(is.numeric)"

Complex expressions can now make the round trip:

agent_pre <- create_agent(~ small_table) |> 
  col_vals_lt(
    columns = where(is.numeric) & starts_with("c"),
    value = 8
  )
yaml_agent_string(agent_pre)
#> type: agent
#> tbl: ~small_table
#> tbl_name: ~small_table
#> label: '[2023-11-06|11:34:30]'
#> lang: en
#> locale: en
#> steps:
#> - col_vals_lt:
#>     columns: where(is.numeric) & starts_with("c")
#>     value: 8.0

agent_yaml <- tempfile()
yaml_write(agent_pre, expanded = FALSE, filename = agent_yaml)
agent_post <- yaml_read_agent(agent_yaml)
yaml_agent_string(agent_post)
#> type: agent
#> tbl: ~small_table
#> tbl_name: ~small_table
#> label: '[2023-11-06|11:34:30]'
#> lang: en
#> locale: en
#> steps:
#> - col_vals_lt:
#>     columns: where(is.numeric) & starts_with("c")
#>     value: 8.0

Preserves old behavior of resolving the expr to column names when expand=TRUE (again, c("c") instead of vars(c)):

agent_pre <- create_agent(~ small_table) |> 
  col_vals_lt(
    columns = where(is.numeric) & starts_with("c"),
    value = 8
  )
yaml_agent_string(agent_pre, expanded = TRUE)
#> type: agent
#> tbl: ~small_table
#> tbl_name: ~small_table
#> label: '[2023-11-06|11:38:46]'
#> lang: en
#> locale: en
#> steps:
#> - col_vals_lt:
#>     columns: c("c")
#>     value: 8.0

agent_yaml <- tempfile()
yaml_write(agent_pre, expanded = TRUE, filename = agent_yaml)
agent_post <- yaml_read_agent(agent_yaml)
yaml_agent_string(agent_post)
#> type: agent
#> tbl: ~small_table
#> tbl_name: ~small_table
#> label: '[2023-11-06|11:38:46]'
#> lang: en
#> locale: en
#> steps:
#> - col_vals_lt:
#>     columns: c("c")
#>     value: 8.0

@rich-iannone rich-iannone self-requested a review November 6, 2023 16:55
Copy link
Member

@rich-iannone rich-iannone left a comment

Choose a reason for hiding this comment

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

Looks great!

@yjunechoe yjunechoe merged commit 6c6b8fd into rstudio:main Nov 6, 2023
13 checks passed
@yjunechoe yjunechoe deleted the tidyselect-yaml branch November 6, 2023 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants