NewGraphEnvironment / fish_passage_bulkley_2020_reporting

https://newgraphenvironment.github.io/fish_passage_bulkley_2020_reporting/
Apache License 2.0
1 stars 2 forks source link

`kableExtra`- ! undefined columns selected, build issue #41

Closed lucy-schick closed 6 days ago

lucy-schick commented 1 month ago

Issue I am running into when trying to build.

processing file: Bulkley.Rmd
  |..............                                                                     |  17% [tab-habitat-summary-58159]                                                   [tab-culvert-bcfp-58159]                                                      [tab-culvert-58159]                                                           [photo-3139-d01]                      
Quitting from lines  at lines 1683-1684 [tab-culvert-bcfp-58159] (Bulkley.Rmd)
Error in `[.data.frame`:
! undefined columns selected
Backtrace:
 1. global print_tab_summary_bcfp()
 4. kableExtra::add_footnote(...)
 6. base::`[.data.frame`(ids.ops, , notation)

Issue is arising from print_tab_summary_bcfp function, something in the kableExtra(addfootnote()) call I think.

lucy-schick commented 1 month ago

Solved this issue by moving the kableExtra::add_footnote call to after kableExtra::kable_styling call, in the print_tab_summary_bcfp function. See code below. I'm not exactly sure why this works, but maybe the table needs to to fully styed before adding a footnote. Also want to mention that I tested changing the notation type to "alphabet' and 'none' in the original code and I got no errors, so the issue was irising when notation = 'symbol'. And to solve this I had to change the order of calls mentioned above.

##this is in two places and should not be - see 0355-tables-reporting-html
print_tab_summary_bcfp <- function(site = my_site, font = 11, ...){
  make_tab_summary_bcfp(site = site) %>%
    kable(caption = paste0('Summary of fish habitat modelling for PSCIS crossing ', site, '.'), booktabs = T) %>%
    kableExtra::kable_styling(c("condensed"), full_width = T, font_size = font) |>
    kableExtra::add_footnote('Model data is preliminary and subject to adjustments.', notation = 'symbol')

}
NewGraphEnvironment commented 1 month ago

Very nice!!

If you run into similar sorts of issues with local functions - test fpr functions that are equivalent and see if those run fine. If they do, we can likely do a find in files search and replace and replace the local function with fpr function. that saves us from doing a whole ton of doctoring of local functions that are already replicated elsewhere and likely much more up-to-date . Could definitely be more complex than that but probably worth testing at the beginning.

lucy-schick commented 1 month ago

okay sounds good

lucy-schick commented 1 month ago

There is an equivalent fpr function fpr_table_bcfp_html which relies on fpr_table_bcfp. I tested this function in the Skeena 2022 report and I get the same error as above, so I think the fpr function needs some edits, I will make an issue for this.

fpr_table_bcfp_html and the local print_tab_summary_bcfp functions only have a couple differences so I will update the local function with the fpr version, but keep the kableExtra call order as mentioned above to avoid errors.

lucy-schick commented 1 month ago

Same issue with print_tab_summary. Reordered and works fine now.