Gt: tidyselect-based improvements

Created on 17 Jun 2020  Â·  3Comments  Â·  Source: rstudio/gt


When trying to apply some type of adjustment to multiple columns, I would typically want to do:
col_1:col_n, this fails w/ vars(), which forces the user to move to naming every column. This is fine for small tables, but could be a bad UX for many col names.

reprex

library(gt)

# Fails 
gtcars %>%
  head() %>% 
  gt() %>% 
  tab_spanner(
    label = "Gas Mileage",
    columns = vars(
      mpg_c:mpg_h
    )
  )
#> Error: Can't convert a call to a string


# works
gtcars %>%
  head() %>% 
  gt() %>% 
  tab_spanner(
    label = "Gas Mileage",
    columns = vars(
      mpg_c, mpg_h
    )
  )
mfr model year trim bdy\_style hp hp\_rpm trq trq\_rpm Gas Mileage drivetrain trsmn ctry\_origin msrp
mpg\_c mpg\_h
Ford GT 2017 Base Coupe coupe 647 6250 550 5900 11 18 rwd 7a United States 447000
Ferrari 458 Speciale 2015 Base Coupe coupe 597 9000 398 6000 13 17 rwd 7a Italy 291744
Ferrari 458 Spider 2015 Base convertible 562 9000 398 6000 13 17 rwd 7a Italy 263553
Ferrari 458 Italia 2014 Base Coupe coupe 562 9000 398 6000 13 17 rwd 7a Italy 233509
Ferrari 488 GTB 2016 Base Coupe coupe 661 8000 561 3000 15 22 rwd 7a Italy 245400
Ferrari California 2015 Base Convertible convertible 553 7500 557 4750 16 23 rwd 7a Italy 198973

Created on 2020-06-17 by the reprex package (v0.3.0)

[2] Intermediate [3] High [3] High ★ Enhancement

Most helpful comment

Given the tidyselect improvements we made in a recent PR, @jthomasmock 's example code now works!

The revised code (sans vars()) is:

gtcars %>%
  head() %>% 
  gt() %>% 
  tab_spanner(
    label = "Gas Mileage",
    columns = mpg_c:mpg_h
  )

The table looks like this:

table

woohoo-gif-26

All 3 comments

Please add tidy_select option when selecting column names :

Example:
columns = vars(ends_with("old"))

This is pretty overdue. Definitely need to overhaul tidyselect support, thanks!

Given the tidyselect improvements we made in a recent PR, @jthomasmock 's example code now works!

The revised code (sans vars()) is:

gtcars %>%
  head() %>% 
  gt() %>% 
  tab_spanner(
    label = "Gas Mileage",
    columns = mpg_c:mpg_h
  )

The table looks like this:

table

woohoo-gif-26

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Torvaney picture Torvaney  Â·  3Comments

vikram-rawat picture vikram-rawat  Â·  3Comments

steveputman picture steveputman  Â·  3Comments

scotbader8858 picture scotbader8858  Â·  4Comments

rich-iannone picture rich-iannone  Â·  4Comments