Skip to content

Commit

Permalink
fix: prevent package 'export' to break
Browse files Browse the repository at this point in the history
- guess_size can't be set to TRUE by default unless a change
in an example of 'export'
  • Loading branch information
davidgohel committed Jan 26, 2023
1 parent 9fe5643 commit 80e52be
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: officer
Type: Package
Title: Manipulation of Microsoft Word and PowerPoint Documents
Version: 0.5.2.005
Version: 0.5.2.006
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
5 changes: 2 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

## Features

- if magick is available, image size will be read and
do not need to be provided.

- if magick is available and argument `guess_size=TRUE`, image
size is read and do not need to be provided.

## Issues

Expand Down
13 changes: 4 additions & 9 deletions R/ooxml_run_objects.R
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,6 @@ docx_section_type <- c("continuous", "evenPage", "nextColumn", "nextPage", "oddP
#'
#' A Section properties object stores information about page composition,
#' such as page size, page orientation, borders and margins.
#' @note
#' There is no support yet for header and footer contents definition.
#' @param page_size page dimensions, an object generated with function [page_size].
#' @param page_margins page margins, an object generated with function [page_mar].
#' @param type Section type. It defines how the contents of the section will be
Expand Down Expand Up @@ -894,11 +892,8 @@ to_wml.prop_section <- function(x, add_ns = FALSE, ...) {
#' @param width,height size of the image file. It can be ignored
#' if parameter `guess_size=TRUE`, see parameter `guess_size`.
#' @param guess_size If package 'magick' is installed, this option
#' can be used (set it to `TRUE` and don't provide values for paramters
#' `width` and `height`). When the flextable will be printed,
#' the images will be read and width and height will be guessed. This
#' should be avoid if possible as it can be an extensive task when
#' several images.
#' can be used (set it to `TRUE`). The images will be read and
#' width and height will be guessed.
#' @param unit unit for width and height, one of "in", "cm", "mm".
#' @param alt alternative text for images
#' @inheritSection ftext usage
Expand All @@ -925,7 +920,7 @@ to_wml.prop_section <- function(x, add_ns = FALSE, ...) {
#' print(x, target = tempfile(fileext = ".docx"))
#' @seealso [ph_with], [body_add], [fpar]
#' @family run functions for reporting
external_img <- function(src, width = NULL, height = NULL, unit = "in", guess_size = TRUE, alt = "") {
external_img <- function(src, width = .5, height = .2, unit = "in", guess_size = FALSE, alt = "") {
# note: should it be vectorized
check_src <- all(grepl("^rId", src)) || all(file.exists(src))
if( !check_src ){
Expand All @@ -940,7 +935,7 @@ external_img <- function(src, width = NULL, height = NULL, unit = "in", guess_si
if( length(height) == 1 ) height <- rep(height, length(src))
}

if (guess_size && (is.null(width) || is.null(height))) {
if (guess_size) {
if (!requireNamespace("magick", quietly = TRUE)) {
stop("package magick is required when using `guess_size` option.")
}
Expand Down
13 changes: 5 additions & 8 deletions man/external_img.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions man/prop_section.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-pptx-add.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ test_that("img dims in pptx", {
value = external_img(img.file),
location = ph_location(left = 1, top = 1,
height = 1.06, width = 1.39),
use_loc_size = FALSE)
use_loc_size = TRUE)
sm <- slide_summary(doc)

expect_equal(nrow(sm), 1)
Expand Down

0 comments on commit 80e52be

Please sign in to comment.