diff --git a/DESCRIPTION b/DESCRIPTION index 0f2f8f5..296f303 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: docorator Title: Docorate (Decorate + Output) Displays -Version: 0.7.0 +Version: 0.7.0.9000 Authors@R: c( person(given = "Shannon", family = "Haughton", email = "shannon.l.haughton@gsk.com", role = c("aut", "cre")), diff --git a/NEWS.md b/NEWS.md index e66c327..0513344 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# docorator (development version) +Improvements +* Check that display objects are not empty before processing with as_docorator (#125) + # docorator 0.7.0 Improvements * Added Word (.docx) output support with the new render_docx() engine. (#97) diff --git a/R/docorate.R b/R/docorate.R index 2cdd345..ba1b8b6 100644 --- a/R/docorate.R +++ b/R/docorate.R @@ -182,6 +182,7 @@ as_docorator <- function( # check inputs check_fancyhdr(header, chr_ok = TRUE) check_fancyhdr(footer) + check_display(x) # prep displays for render x <- prep_display( diff --git a/R/utils.R b/R/utils.R index 6c9441c..3abd94a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -346,4 +346,17 @@ prep_display <- function(x, fig_dim = c(5,8), convert_ggplot = TRUE, fontsize = ) x +} + +#' Check that the display object is not empty +#' @param x object passed to `as_docorator` +#' @noRd +#' +check_display <- function(x) { + if(rlang::is_empty(x)) { + cli::cli_abort( + "The {.arg {rlang::caller_arg(x)}} argument cannot be empty or NULL. Please provide a valid display object.", + call = rlang::caller_env() + ) + } } \ No newline at end of file diff --git a/tests/testthat/test_docorate.R b/tests/testthat/test_docorate.R index 4696f5c..c586899 100644 --- a/tests/testthat/test_docorate.R +++ b/tests/testthat/test_docorate.R @@ -90,3 +90,21 @@ test_that("Create docorator object without display_name errors",{ }) + +test_that("Create docorator object with invalid display errors",{ + + expect_error(as_docorator( + x = list(), + display_name = "empty_list", + save_object = FALSE + ), + "The `x` argument cannot be empty or NULL. Please provide a valid display object.") + + expect_error(as_docorator( + x = NULL, + display_name = "null_object", + save_object = FALSE + ), + "The `x` argument cannot be empty or NULL. Please provide a valid display object.") + +})