Skip to content

Commit 3b9f1a6

Browse files
committed
error message when adding NULL to officer helper
fixes #104
1 parent 24601d1 commit 3b9f1a6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ importFrom(rlang,as_function)
225225
importFrom(rlang,as_string)
226226
importFrom(rlang,call_args)
227227
importFrom(rlang,call_match)
228+
importFrom(rlang,caller_arg)
228229
importFrom(rlang,caller_env)
229230
importFrom(rlang,check_dots_empty)
230231
importFrom(rlang,check_dots_unnamed)

R/officer.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ body_add_crosstable = function (doc, x, body_fontsize=NULL,
3939
padding_v=NULL,
4040
allow_break=TRUE,
4141
max_cols=25, ...) {
42+
if(is.null(x)){
43+
cli_abort("{caller_arg(x)} is NULL")
44+
}
4245
assert_class(x, "crosstable", .var.name=vname(x))
4346

4447
if(missing(padding_v)) padding_v = getOption("crosstable_padding_v", NULL)
@@ -686,7 +689,7 @@ body_add_img2 = function(doc, src, width, height,
686689
#' @author Dan Chaltiel
687690
#' @export
688691
#' @importFrom checkmate assert_class
689-
#' @importFrom rlang check_installed
692+
#' @importFrom rlang caller_arg check_installed
690693
#' @examples
691694
#' library(officer)
692695
#' library(ggplot2)
@@ -709,6 +712,9 @@ body_add_gg2 = function(doc, value,
709712
add_legend=TRUE, bookmark=NULL,
710713
res = 300, ... ){
711714
check_installed("ggplot2", reason="for function `body_add_gg2()` to work.")
715+
if(is.null(value)){
716+
cli_abort("{caller_arg(value)} is NULL")
717+
}
712718
assert_class(value, "ggplot")
713719
units = match.arg(units, c("in", "cm", "mm"))
714720
file = tempfile(fileext=".png")
@@ -749,6 +755,9 @@ body_add_gg2 = function(doc, value,
749755
#' write_and_open(doc)
750756
body_add_flextable2 = function(doc, x, bookmark=NULL, append_line=TRUE, ...){
751757
legend = attr(x, "legend")
758+
if(is.null(x)){
759+
cli_abort("{caller_arg(x)} is NULL")
760+
}
752761
if(!is.null(legend)){
753762
doc = body_add_table_legend(doc, legend=legend, bookmark=bookmark)
754763
}

0 commit comments

Comments
 (0)