diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e5e29d471e32ea3445dec27ce79d0ac4a7863a10..28ea7a7d3614eb06da624d47aed2dbdbe1abffeb 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,7 +3,7 @@ { "name": "R (rocker/geospatial)", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "rocker/geospatial:latest", + "image": "rocker/geospatial:4.4.1", "customizations": { "vscode": { "extensions": [ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8fe16fa6a505467f630faacc54c205a5bf22ea05..f9e126056f520f8317c1b0f33f86b51afa699be7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ stages: default: tags: [docker] -image: rocker/verse:devel +image: rocker/geospatial:latest variables: CACHE_CI: "$CI_PROJECT_DIR/ci" diff --git a/DESCRIPTION b/DESCRIPTION index f4e591afe4c178346ee802b5be155ce2925c4735..1f00dbdf447e847223f195a84675a1fb36a298bb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,7 @@ Description: R-package proposing a framework to apply FAIR principles based on r License: AGPL (>= 3) Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Imports: bookdown, config, @@ -16,11 +16,13 @@ Imports: dplyr, fs, gert, + graphics, httr, jsonlite, magrittr, pkgdown, pkgload, + png, readr, rlang, rticles, diff --git a/NAMESPACE b/NAMESPACE index b164b7e2894f451094eedd4a26b67b256aa6ddb8..6c81ee2af48f0847938f3a0797881cd117a37f36 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export(loadConfig) export(mermaid) export(mermaid_gen_link) export(pkg_sys) +export(plot_png) export(purge_string) export(render_report) export(render_report_setup) diff --git a/R/plot_png.R b/R/plot_png.R new file mode 100644 index 0000000000000000000000000000000000000000..7aeb9d3e72009e9af7295e507733ac9e071f81ac --- /dev/null +++ b/R/plot_png.R @@ -0,0 +1,43 @@ +#' Plot a PNG file +#' +#' @details +#' This function offers two advantages for displaying images in reports +#' or vignettes instead of markdown syntax or [knitr::include_graphics()]: +#' - The size of the image is controlled by the chunk parameters +#' - Image files stored outside the report or vignette folder are correctly +#' rendered in HTML +#' +#' @source From https://stackoverflow.com/a/28729601/5300212 +#' @param path Path of the file +#' @param add [logical] Add the image to the existing plot +#' +#' @return Nothing, used to side effect. +#' @export +#' +#' @examples +#' plot_png(system.file("img", "Rlogo.png", package="png")) +plot_png <- function(path, add = FALSE) { + # read the file + pic <- png::readPNG(path, native = TRUE) + res <- dim(pic)[2:1] # get the resolution, [x, y] + if (!add) { + opar <- par(mar = c(0, 0, 0, 0)) + plot( + 1, + 1, + xlim = c(1, res[1]), + ylim = c(1, res[2]), + asp = 1, + type = 'n', + xaxs = 'i', + yaxs = 'i', + xaxt = 'n', + yaxt = 'n', + xlab = '', + ylab = '', + bty = 'n' + ) + par(opar) + } + graphics::rasterImage(pic, 1, 1, res[1], res[2], xpd = TRUE) +} diff --git a/R/render_report.R b/R/render_report.R index d6a82d1597504cb74049868d5c4acb5dae1701dc..07c12937c19c493a15932cbf5341630e392f48af 100644 --- a/R/render_report.R +++ b/R/render_report.R @@ -40,6 +40,9 @@ render_report <- function(input, "`install.packages('tinytex')`\n", "`tinytex::install_tinytex()`") } + if (!tinytex::is_tinytex() && !Sys.getenv("FAIRIFY_TINYTEX") == "0") { + tinytex::install_tinytex(force = TRUE) + } if (file.exists(file.path(input, "_bookdown.yml"))) { babel_lang <- yaml::read_yaml("_bookdown.yml")$babel_lang diff --git a/R/render_reports.R b/R/render_reports.R index a46082da24e61df29b1c0fc2e87821adee13845a..645012829e92282666a672d4ab0d9bdf4eb95cba 100644 --- a/R/render_reports.R +++ b/R/render_reports.R @@ -8,6 +8,12 @@ #' called in the first chunk of the report in order to make the templates available #' for rendering. #' +#' @details +#' TinyTeX is automatically installed by default when rendering a report in PDF +#' format. +#' This can be avoided by defining the environnement variable +#' `FAIRIFY_TINYTEX=0`. +#' #' @inheritParams list_reports #' @param publish_dir [character] rendering output path (root folder of the reports) #' @param ... Parameters passed to [render_report] and [bookdown::render_book] diff --git a/man/plot_png.Rd b/man/plot_png.Rd new file mode 100644 index 0000000000000000000000000000000000000000..9e87400761245edd5dd2609949aedcef0ffd0eca --- /dev/null +++ b/man/plot_png.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/plot_png.R +\name{plot_png} +\alias{plot_png} +\title{Plot a PNG file} +\source{ +From https://stackoverflow.com/a/28729601/5300212 +} +\usage{ +plot_png(path, add = FALSE) +} +\arguments{ +\item{path}{Path of the file} + +\item{add}{\link{logical} Add the image to the existing plot} +} +\value{ +Nothing, used to side effect. +} +\description{ +Plot a PNG file +} +\details{ +This function offers two advantages for displaying images in reports +or vignettes instead of markdown syntax or \code{\link[knitr:include_graphics]{knitr::include_graphics()}}: +\itemize{ +\item The size of the image is controlled by the chunk parameters +\item Image files stored outside the report or vignette folder are correctly +rendered in HTML +} +} +\examples{ +plot_png(system.file("img", "Rlogo.png", package="png")) +} diff --git a/man/render_reports.Rd b/man/render_reports.Rd index bf2a9a7f43712556c0b9687cdcdeaefe1e7d8753..4cd560a8484772363dff79eb3546497367c1f82f 100644 --- a/man/render_reports.Rd +++ b/man/render_reports.Rd @@ -64,6 +64,11 @@ duplicate labels (set the option \code{knitr.duplicate.label = "allow"})} \code{render_report_setup} prepare the report for rendering. This function should be called in the first chunk of the report in order to make the templates available for rendering. + +TinyTeX is automatically installed by default when rendering a report in PDF +format. +This can be avoided by defining the environnement variable +\code{FAIRIFY_TINYTEX=0}. } \examples{ # Create a fairify project in a temporary folder