Running GT Example causes Error: object 'num' not found

Hi,

I am playing around with the package gt and am trying to run the code from the example here

I am running into trouble with the num column. If i quote it, it seems to be ok in the first section but then i run into problems in the second call where quoting wont fix it (columns = num)

# Use `exibble` to create a gt table;
# add styles that are to be applied
# to data cells that satisfy a
# condition (using `tab_style()`)
library(gt)
#> Warning: package 'gt' was built under R version 4.0.5
exibble %>%
  dplyr::select(num, currency) %>%
  gt() %>%
  fmt_number(
    columns = c(num, currency),
    decimals = 1
  ) %>%
  tab_style(
    style = list(
      cell_fill(color = "lightcyan"),
      cell_text(weight = "bold")
    ),
    locations = cells_body(
      columns = num,
      rows = num >= 5000
    )
  ) %>%
  tab_style(
    style = list(
      cell_fill(color = "#F9E3D6"),
      cell_text(style = "italic")
    ),
    locations = cells_body(
      columns = currency,
      rows = currency < 100
    )
  )
#> Error: object 'num' not found

Thanks very much for your help

I noticed the same recently. The issue is captured here with a few options to resolve:
Documentation issue: c() is used instead of vars() in example on https://gt.rstudio.com/reference/tab_spanner.html · Issue #733 · rstudio/gt · GitHub

Can anybody at RStudio confirm the cause as neither gt nor tidyselect have changed in a long time. Was it a recent dplyr update?

I have noticed other problems where the examples and/or the documentation is wrong. I'll post them if RStudio show any interest.

1 Like

Hi @martin.R

Thanks to your link i was able to create what i was looking for with the below code. I just quoted all the items causing the errors

# Use `exibble` to create a gt table;
# add styles that are to be applied
# to data cells that satisfy a
# condition (using `tab_style()`)
library(gt)
#> Warning: package 'gt' was built under R version 4.0.5
exibble %>%
  dplyr::select(num, currency) %>%
  gt() %>%
  fmt_number(
    columns = c("num", "currency"),
    decimals = 1
  ) %>%
  tab_style(
    style = list(
      cell_fill(color = "lightcyan"),
      cell_text(weight = "bold")
    ),
    locations = cells_body(
      columns = "num",
      rows = "num" >= 5000
    )
  ) %>%
  tab_style(
    style = list(
      cell_fill(color = "#F9E3D6"),
      cell_text(style = "italic")
    ),
    locations = cells_body(
      columns = c("currency"),
      rows = c("currency") < 100
    )
  )

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.