From 2f89c8787ccd820c50cb77fda9345765f3e95990 Mon Sep 17 00:00:00 2001 From: David Gohel Date: Mon, 28 Oct 2024 00:06:50 +0100 Subject: [PATCH] fix: improve error checking for plot hook - check image is not an url - mention in the manual fix #146 --- DESCRIPTION | 8 ++++---- R/hooks.R | 5 +++++ R/rdocx_document.R | 5 ++++- man/rdocx_document.Rd | 7 +++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index cb12284..cd63902 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: officedown Type: Package Title: Enhanced 'R Markdown' Format for 'Word' and 'PowerPoint' -Version: 0.4.0.002 +Version: 0.4.0.003 Authors@R: c( person("David", "Gohel", role = c("aut", "cre", "cph"), email = "david.gohel@ardata.fr"), @@ -26,13 +26,13 @@ License: MIT + file LICENSE Encoding: UTF-8 Imports: knitr, rmarkdown, - officer (>= 0.5.1), + officer (>= 0.6.7), xml2, rlang, uuid, grDevices, yaml, utils, memoise, - rvg (>= 0.2.2) + rvg (>= 0.3.4) Suggests: ggplot2, - flextable (>= 0.7.0), + flextable (>= 0.9.7), bookdown (>= 0.13), testthat (>= 3.0.0), doconv (>= 0.3.0) diff --git a/R/hooks.R b/R/hooks.R index 62019e3..9d1ecc7 100644 --- a/R/hooks.R +++ b/R/hooks.R @@ -12,6 +12,11 @@ knitr_opts_current <- function(x, default = FALSE){ #' @noRd plot_word_fig_caption <- function(x, options) { + if (grepl("^(ftp|ftps|http|https)://", x[1])) { + stop("Images in 'rdocx_document' must be local files accessible without an internet connection:\n", + shQuote(x[1]), call. = FALSE) + } + if(!is.character(options$fig.cap)) options$fig.cap <- NULL if(!is.character(options$fig.alt)) options$fig.alt <- NULL if(is.null(options$fig.id)) diff --git a/R/rdocx_document.R b/R/rdocx_document.R index 8a99868..322def1 100644 --- a/R/rdocx_document.R +++ b/R/rdocx_document.R @@ -164,7 +164,10 @@ get_reference_rdocx <- memoise(get_docx_uncached) #' #' ```{r child = "man/rdocx/rmarkdown-yaml.Rmd"} #' ``` -#' +#' @section Known limitations: +#' When using `knitr::include_graphics()` in 'rdocx_document', +#' the image must be local, while with standard 'R Markdown' +#' output documents, images located on Internet are supported. #' @examples #' # rdocx_document basic example ----- #' @example examples/rdocx_document.R diff --git a/man/rdocx_document.Rd b/man/rdocx_document.Rd index cbcee17..7a11655 100644 --- a/man/rdocx_document.Rd +++ b/man/rdocx_document.Rd @@ -337,6 +337,13 @@ output: }\if{html}{\out{}} } +\section{Known limitations}{ + +When using \code{knitr::include_graphics()} in 'rdocx_document', +the image must be local, while with standard 'R Markdown' +output documents, images located on Internet are supported. +} + \examples{ # rdocx_document basic example ----- library(rmarkdown)