Appsilon / data.validator

validate your data and create nice reports straight from R
https://appsilon.github.io/data.validator/
Other
145 stars 14 forks source link

[Bug]: Saving report fails if there are validation warnings #92

Open chrisbrownlie opened 8 months ago

chrisbrownlie commented 8 months ago

Guidelines

Project Version

2.4.1

Platform and OS Version

Windows 10

Existing Issues

No response

What happened?

When using save_report() for a report that has validation warnings, an error is thrown due to a missing df_error_head_n argument.

Steps to reproduce

You can use a simplified version of the first example on the 'All you need to know about 'data.validator' vignette.

library(assertr)
library(dplyr)

report <- data_validation_report()

validate(mtcars) %>%
  validate_cols(description = "vs and am values should equal 3 or 4",
                skip_chain_opts = TRUE,
                error_fun = warning_append, in_set(c(3, 4)), gear, carb) %>%
  add_results(report)

save_report(report)
#> 
#> Quitting from lines 12-13 [generate_report] (skeleton.Rmd)
#> Error in `purrr::map()`:
#> ℹ In index: 1.
#> Caused by error in `purrr::map()`:
#> ℹ In index: 1.
#> Caused by error in `purrr::map()`:
#> ℹ In index: 1.
#> Caused by error in `make_accordion_element()`:
#> ! argument "df_error_head_n" is missing, with no default
#> Backtrace:
#>      ▆
#>   1. ├─params$generate_report_html(params$extra_params)
#>   2. │ ├─base::do.call(private$report_constructor, params_list) at data.validator/R/report.R:51:6
#>   3. │ └─data.validator (local) `<fn>`(validation_results = `<tibble[,8]>`)
#>   4. │   ├─... %>% htmlwidgets::onRender(post_render_js) at data.validator/R/semantic_report_constructors.R:408:2
#>   5. │   └─data.validator:::get_semantic_report_ui(...)
#>   6. │     └─... %>% htmltools::div() at data.validator/R/semantic_report_constructors.R:359:2
#>   7. ├─htmlwidgets::onRender(., post_render_js)
#>   8. │ └─htmlwidgets:::addHook(x, "render", jsCode, data)
#>   9. ├─shiny.semantic::uirender(., width = "100%", height = "100%")
#>  10. │ └─base::toString(ui)
#>  11. ├─htmltools::div(.)
#>  12. │ └─rlang::dots_list(...)
#>  13. ├─purrr::map(...)
#>  14. │ └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>  15. │   ├─purrr:::with_indexed_errors(...)
#>  16. │   │ └─base::withCallingHandlers(...)
#>  17. │   ├─purrr:::call_with_cleanup(...)
#>  18. │   └─data.validator (local) .f(.x[[i]], ...)
#>  19. │     └─... %>% ... at data.validator/R/semantic_report_constructors.R:360:4
#>  20. ├─data.validator:::display_results(...)
#>  21. │ ├─data.validator:::segment(...) at data.validator/R/semantic_report_constructors.R:253:2
#>  22. │ │ └─htmltools::div(...) at data.validator/R/semantic_report_constructors.R:8:2
#>  23. │ │   └─rlang::dots_list(...)
#>  24. │ ├─data.validator:::make_accordion_container(...)
#>  25. │ │ ├─htmltools::tagList(...) at data.validator/R/semantic_report_constructors.R:174:2
#>  26. │ │ │ └─rlang::dots_list(...)
#>  27. │ │ └─htmltools::div(...)
#>  28. │ │   └─rlang::dots_list(...)
#>  29. │ └─data.validator:::make_accordion_element(...)
#>  30. │   ├─htmltools::tagList(...) at data.validator/R/semantic_report_constructors.R:205:2
#>  31. │   │ └─rlang::dots_list(...)
#>  32. │   ├─htmltools::div(...)
#>  33. │   │ └─rlang::dots_list(...)
#>  34. │   └─data.validator:::result_table(results, type, mark, df_error_head_n)
#>  35. │     ├─htmltools::tags$table(...) at data.validator/R/semantic_report_constructors.R:138:4
#>  36. │     │ └─rlang::dots_list(...)
#>  37. │     ├─htmltools::tags$tbody(...)
#>  38. │     │ └─rlang::dots_list(...)
#>  39. │     └─purrr::map(...)
#>  40. │       └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>  41. │         ├─purrr:::with_indexed_errors(...)
#>  42. │         │ └─base::withCallingHandlers(...)
#>  43. │         ├─purrr:::call_with_cleanup(...)
#>  44. │         └─data.validator (local) .f(.x[[i]], ...)
#>  45. │           └─data.validator:::make_table_row(results[.x, ], type, mark, df_error_head_n = df_error_head_n)
#>  46. │             ├─htmltools::div(...) at data.validator/R/semantic_report_constructors.R:88:4
#>  47. │             │ └─rlang::dots_list(...)
#>  48. │             ├─htmltools::div(...)
#>  49. │             │ └─rlang::dots_list(...)
#>  50. │             ├─htmltools::div(...)
#>  51. │             │ └─rlang::dots_list(...)
#>  52. │             ├─htmltools::tagList(prepare_modal_content(results, df_error_head_n))
#>  53. │             │ └─rlang::dots_list(...)
#>  54. │             └─data.validator:::prepare_modal_content(results, df_error_head_n)
#>  55. │               ├─... %>% htmltools::tagList() at data.validator/R/semantic_report_constructors.R:25:2
#>  56. │               └─purrr::map(...)
#>  57. │                 └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
#>  58. │                   ├─purrr:::with_indexed_errors(...)
#>  59. │                   │ └─base::withCallingHandlers(...)
#>  60. │                   ├─purrr:::call_with_cleanup(...)
#>  61. │                   └─data.validator (local) .f(.x[[i]], ...)
#>  62. │                     ├─htmltools::div(...) at data.validator/R/semantic_report_constructors.R:26:4
#>  63. │                     │ └─rlang::dots_list(...)
#>  64. │                     ├─htmltools::HTML(...)
#>  65. │                     ├─knitr::kable(...)
#>  66. │                     ├─utils::head(error$error_df[[1]][[.x]], n = df_error_head_n)
#>  67. │                     └─utils (local) head.data.frame(error$error_df[[1]][[.x]], n = df_error_head_n)
#>  68. │                       └─utils:::checkHT(n, d <- dim(x))
#>  69. ├─htmltools::tagList(.)
#>  70. │ └─rlang::dots_list(...)
#>  71. └─base::.handleSimpleError(...)
#>  72.   └─purrr (local) h(simpleError(msg, call))
#>  73.     └─cli::cli_abort(...)
#>  74.       └─rlang::abort(...)

Created on 2023-12-21 with reprex v2.0.2

Expected behavior

An error shouldn't occur. The issue is that the df_error_head_n argument is not being passed to the make_accordion_element() for validation warnings, in display_results(). So if I understand correctly I think its just a one-line fix.

This is assuming that it should be the same and not a separate df_warning_head_n argument. Hope that makes sense.

Attachments

No response

Screenshots or Videos

No response

Additional Information

As this is a relatively small, simple change I'm happy to raise a PR for it myself if you'd prefer. Just let me know!

dsen6644 commented 4 months ago

This issue seems to still be present?