From e30c2744355ae5f8f05fced5c7bac9141bb429da Mon Sep 17 00:00:00 2001 From: David Gohel Date: Sun, 5 May 2024 16:34:26 +0200 Subject: [PATCH] tests: test opts_current_table() --- DESCRIPTION | 88 +++++++++++++++---------- tests/testthat/docs_dir/knitr-utils.Rmd | 17 +++++ tests/testthat/test-knitr-utils.R | 26 ++++++++ 3 files changed, 98 insertions(+), 33 deletions(-) create mode 100644 tests/testthat/docs_dir/knitr-utils.Rmd create mode 100644 tests/testthat/test-knitr-utils.R diff --git a/DESCRIPTION b/DESCRIPTION index 05040d59..3e75652d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,41 +1,63 @@ -Package: officer Type: Package +Package: officer Title: Manipulation of Microsoft Word and PowerPoint Documents -Version: 0.6.6.008 +Version: 0.6.6.009 Authors@R: c( - person("David", "Gohel", role = c("aut", "cre"), email = "david.gohel@ardata.fr"), - person("Stefan", "Moog", role = "aut", email = 'moogs@gmx.de'), - person(given = "ArData", role = "cph"), - person("Frank", "Hangler", role = "ctb", email = "frank@plotandscatter.com", comment = "function body_replace_all_text"), - person("Liz", "Sander", role = "ctb", email = 'lsander@civisanalytics.com', comment = "several documentation fixes"), - person("Anton", "Victorson", role = "ctb", email = 'anton@victorson.se',comment = "fixes xml structures"), - person("Jon", "Calder", role = "ctb", email = 'jonmcalder@gmail.com', comment = "update vignettes"), - person("John", "Harrold", role = "ctb", email = 'john.m.harrold@gmail.com', comment = "function annotate_base"), - person("John", "Muschelli", role = "ctb", email = 'muschellij2@gmail.com', comment = "google doc compatibility"), - person("Bill", "Denney", email="wdenney@humanpredictions.com", role="ctb", comment=c(ORCID="0000-0002-5759-428X", "function as.matrix.rpptx")), - person("Nikolai", "Beck", role = "ctb", email = 'beck.nikolai@gmail.com', comment = "set speaker notes for .pptx documents"), - person("Greg", "Leleu", role = "ctb", email = 'gregoire.leleu@gmail.com', comment = "fields functionality in ppt"), - person("Hongyuan", "Jia", role = "ctb", email = "hongyuanjia@cqust.edu.cn", comment = c(ORCID = "0000-0002-0075-8183")) - ) -Description: Access and manipulate 'Microsoft Word', 'RTF' and 'Microsoft PowerPoint' documents from R. - The package focuses on tabular and graphical reporting from R; it also provides two functions - that let users get document content into data objects. A set of functions - lets add and remove images, tables and paragraphs of text in new or existing documents. - The package does not require any installation of Microsoft products to be able to write Microsoft - files. + person("David", "Gohel", , "david.gohel@ardata.fr", role = c("aut", "cre")), + person("Stefan", "Moog", , "moogs@gmx.de", role = "aut"), + person("ArData", role = "cph"), + person("Frank", "Hangler", , "frank@plotandscatter.com", role = "ctb", + comment = "function body_replace_all_text"), + person("Liz", "Sander", , "lsander@civisanalytics.com", role = "ctb", + comment = "several documentation fixes"), + person("Anton", "Victorson", , "anton@victorson.se", role = "ctb", + comment = "fixes xml structures"), + person("Jon", "Calder", , "jonmcalder@gmail.com", role = "ctb", + comment = "update vignettes"), + person("John", "Harrold", , "john.m.harrold@gmail.com", role = "ctb", + comment = "function annotate_base"), + person("John", "Muschelli", , "muschellij2@gmail.com", role = "ctb", + comment = "google doc compatibility"), + person("Bill", "Denney", , "wdenney@humanpredictions.com", role = "ctb", + comment = c(ORCID = "0000-0002-5759-428X", "function as.matrix.rpptx")), + person("Nikolai", "Beck", , "beck.nikolai@gmail.com", role = "ctb", + comment = "set speaker notes for .pptx documents"), + person("Greg", "Leleu", , "gregoire.leleu@gmail.com", role = "ctb", + comment = "fields functionality in ppt"), + person("Hongyuan", "Jia", , "hongyuanjia@cqust.edu.cn", role = "ctb", + comment = c(ORCID = "0000-0002-0075-8183")) + ) +Description: Access and manipulate 'Microsoft Word', 'RTF' and 'Microsoft + PowerPoint' documents from R. The package focuses on tabular and + graphical reporting from R; it also provides two functions that let + users get document content into data objects. A set of functions lets + add and remove images, tables and paragraphs of text in new or + existing documents. The package does not require any installation of + Microsoft products to be able to write Microsoft files. License: MIT + file LICENSE +URL: https://ardata-fr.github.io/officeverse/, + https://davidgohel.github.io/officer/ +BugReports: https://github.com/davidgohel/officer/discussions Imports: - grDevices, stats, graphics, utils, - zip (>= 2.1.0), + graphics, + grDevices, + openssl, + R6, + ragg, + stats, + utils, + uuid, xml2 (>= 1.1.0), - openssl, R6, uuid, - ragg -URL: https://ardata-fr.github.io/officeverse/, https://davidgohel.github.io/officer/ + zip (>= 2.1.0) +Suggests: + devEMF, + doconv (>= 0.3.0), + ggplot2, + knitr, + magick, + rmarkdown, + rsvg, + testthat Encoding: UTF-8 -BugReports: https://github.com/davidgohel/officer/discussions -RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) -Suggests: testthat, devEMF, ggplot2, - rmarkdown, - doconv (>= 0.3.0), - knitr, rsvg, magick +RoxygenNote: 7.3.1 diff --git a/tests/testthat/docs_dir/knitr-utils.Rmd b/tests/testthat/docs_dir/knitr-utils.Rmd new file mode 100644 index 00000000..401ac042 --- /dev/null +++ b/tests/testthat/docs_dir/knitr-utils.Rmd @@ -0,0 +1,17 @@ +--- +title: "Untitled" +output: md_document +params: + rds_path: temp.RDS +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = FALSE) +``` + +```{r tab.topcaption=FALSE, tab.cap.pre = "Tableau", tab.cap.sep = " :", tab.cap = "Coucou", label="plop", tab.cap.style = "Normal", tab.alt.title = "alt title", tab.alt.description = "alt description"} +saveRDS( + object = officer::opts_current_table(), + params$rds_path +) +``` diff --git a/tests/testthat/test-knitr-utils.R b/tests/testthat/test-knitr-utils.R new file mode 100644 index 00000000..943ef952 --- /dev/null +++ b/tests/testthat/test-knitr-utils.R @@ -0,0 +1,26 @@ +test_that("opts_current_table works as expected", { + skip_if_not_installed("knitr") + skip_if_not_installed("rmarkdown") + skip_if_not(rmarkdown::pandoc_available()) + + new_dir <- tempfile() + dir.create(new_dir, showWarnings = FALSE) + rmd_fp <- file.path(new_dir, "knitr-utils.Rmd") + generated_rds <- tempfile(fileext = ".RDS") + file.copy("docs_dir/knitr-utils.Rmd", to = rmd_fp) + rmarkdown::render( + input = rmd_fp, + envir = parent.frame(), + params = list( + rds_path = generated_rds + ), + quiet = TRUE + ) + x <- readRDS(generated_rds) + expect_equal(x$cap.pre, "Tableau ") + expect_equal(x$cap.style, "Normal") + expect_equal(x$cap.sep, " : ") + expect_equal(x$alt.title, "alt title") + expect_equal(x$alt.description, "alt description") + expect_equal(x$cap, "Coucou") +})