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

"Error in .f(.x[[i]], ...) : object 'values_1' not found" should be updated to more readable error #475

Closed
MadhulikaTanuboddi opened this issue Jan 22, 2020 · 1 comment · Fixed by #1638

Comments

@MadhulikaTanuboddi
Copy link

MadhulikaTanuboddi commented Jan 22, 2020

Run the following example where in one of the footnotes section, we are trying to add a footnote to a column named "valuer" that does not exist in the table

library(gt)
library(tidyverse)

# Create a table with footnotes in various cell types
tbl <-
  dplyr::tribble(
    ~date,        ~rowname,  ~value_1,  ~value_2,
    "2018-02-10", "1",       20.4,      361.1,
    "2018-02-10", "2",       10.9,      743.3,
    "2018-02-10", "3",       34.6,      344.7,
    "2018-02-10", "4",        8.3,      342.3,
    "2018-02-11", "5",       28.3,      234.9,
    "2018-02-11", "6",       75.5,      190.9,
    "2018-02-11", "7",       63.1,        2.3,
    "2018-02-11", "8",       25.8,      184.3,
    "2018-02-11", "9",        5.2,      197.2,
    "2018-02-11", "10",      55.3,      284.6
  )

# Create a display table
footnotes_tbl <-
  gt(data = tbl, groupname_col = "date") %>%
  tab_spanner(
    label = "values",
    columns = starts_with("value")
  ) %>%
  tab_footnote(
    footnote = "This is an even smaller number.",
    locations = cells_body(columns = vars(value_1), rows = 9)
  ) %>%
  tab_footnote(
    footnote = "This is a small number.",
    locations = cells_body(columns = vars(value_1), rows = 4)
  ) %>%
  tab_footnote(
    footnote = "First data cell.",
    locations = cells_body(columns = "valuer", rows = 1)
  ) %>%
  tab_footnote(
    footnote = "The first row group",
    locations = cells_row_groups(groups = ends_with("10"))
  ) %>%
  tab_footnote(
    footnote = "Two sets of values",
    locations = cells_column_spanners(spanners = starts_with("val"))
  ) %>%
  tab_footnote(
    footnote = "A stub cell.",
    locations = cells_stub(rows = 1)
  ) %>%
  tab_footnote(
    footnote = md("`value_1` is the first column of values."),
    locations = cells_column_labels(columns = vars(value_1))
  )

footnotes_tbl

Expected: Readable error saying valuer does not exist
Actual: Error in .f(.x[[i]], ...) : object 'values_1' not found. "Error in f.." does not make sense here

@rich-iannone
Copy link
Member

Running this code now (in the dev version) provides a slightly better error thanks to our better use of tidyselect:

Error: Can't subset columns that don't exist.
x Column `valuer` doesn't exist.

It can still be argued that a better, more descriptive error message can still be provided by gt.

@rich-iannone rich-iannone added this to the v0.4.0 milestone Apr 27, 2021
@rich-iannone rich-iannone modified the milestones: v0.4.0, v0.5.0 Jan 26, 2022
@rich-iannone rich-iannone modified the milestones: v0.5.0, v0.6.0 Apr 11, 2022
@rich-iannone rich-iannone modified the milestones: v0.6.0, v0.7.0 Apr 19, 2022
@rich-iannone rich-iannone modified the milestones: v0.7.0, v0.8.0 May 27, 2022
@rich-iannone rich-iannone modified the milestones: v0.8.0, FUTURE Sep 13, 2022
@olivroy olivroy modified the milestones: FUTURE, v0.11.0 Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants