From d805b73cff4bdfe93875ac56ab929f99d96e4a35 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Mon, 22 Apr 2024 14:37:07 +0200 Subject: [PATCH 1/2] make copying files more robust --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- NAMESPACE | 1 + R/compareScenarios.R | 19 +++++++++++-------- README.md | 6 +++--- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index d0a9fb1..6d42911 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '158648' +ValidationKey: '178515' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 87b9178..11373cc 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'piamPlotComparison: Create comparison plots for your model results' -version: 0.0.8 -date-released: '2024-04-18' +version: 0.0.9 +date-released: '2024-04-22' abstract: A frameworks to create comparison plots for your model results. authors: - family-names: Benke diff --git a/DESCRIPTION b/DESCRIPTION index f537df9..0e2c33d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: piamPlotComparison Title: Create comparison plots for your model results -Version: 0.0.8 -Date: 2024-04-18 +Version: 0.0.9 +Date: 2024-04-22 Authors@R: c( person("Falk", "Benke", , "benke@pik-potsdam.de", role = c("aut", "cre")), person("Christof", "Schoetz", role = "aut") diff --git a/NAMESPACE b/NAMESPACE index 19dc818..2d53e39 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ importFrom(dplyr,left_join) importFrom(dplyr,mutate) importFrom(dplyr,select) importFrom(dplyr,summarize) +importFrom(piamutils,getPackageLocation) importFrom(rlang,.data) importFrom(rlang,.env) importFrom(tidyr,pivot_wider) diff --git a/R/compareScenarios.R b/R/compareScenarios.R index 44e81d2..0516ebd 100644 --- a/R/compareScenarios.R +++ b/R/compareScenarios.R @@ -29,6 +29,7 @@ #' an preprocess data in your global environment during development. #' @param quiet \code{logical(1)}. Suppress printing during rendering? #' @param ... YAML parameters, see below. +#' @importFrom piamutils getPackageLocation #' @return The value returned by \code{\link[rmarkdown:render]{rmarkdown::render()}}. #' @section YAML Parameters: #' \describe{ @@ -162,11 +163,11 @@ compareScenarios <- function( # copy the template directory from the package to the outputDir because # rmarkdown writes to the folder containing the template. templateInOutputDir <- file.path(outputDir, "compareScenarios", "cs_main.Rmd") - file.copy(system.file("compareScenarios", package = "piamPlotComparison"), + file.copy(file.path(piamutils::getPackageLocation("piamPlotComparison"), "compareScenarios"), outputDir, recursive = TRUE) if (!is.null(projectLibrary)) { - file.copy(system.file("compareScenarios", package = projectLibrary), + file.copy(file.path(piamutils::getPackageLocation(projectLibrary), "compareScenarios"), outputDir, recursive = TRUE) } @@ -187,7 +188,7 @@ compareScenarios <- function( # Copies the CompareScenarios-Rmds to the specified location and modifies # their YAML header according to \code{yamlParams}. .compareScenarios2Rmd <- function(projectLibrary, yamlParams, outputDir, outputFile) { - pathMain <- system.file("compareScenarios/cs_main.Rmd", package = "piamPlotComparison") + pathMain <- file.path(piamutils::getPackageLocation("piamPlotComparison"), "compareScenarios/cs_main.Rmd") linesMain <- readLines(pathMain) delimiters <- grep("^(---|\\.\\.\\.)\\s*$", linesMain) headerMain <- linesMain[(delimiters[1]):(delimiters[2])] @@ -211,10 +212,14 @@ compareScenarios <- function( if (!dir.exists(pathDir)) dir.create(pathDir) - dirFiles <- dir(system.file("compareScenarios", package = "piamPlotComparison"), full.names = TRUE) + dirFiles <- dir(file.path(piamutils::getPackageLocation("piamPlotComparison"), "compareScenarios"), + full.names = TRUE) if (!is.null(projectLibrary)) { - dirFiles <- c(dirFiles, dir(system.file("compareScenarios", package = projectLibrary), full.names = TRUE)) + dirFiles <- c(dirFiles, + dir(file.path(piamutils::getPackageLocation(projectLibrary), + "compareScenarios"), + full.names = TRUE)) } rmdDirFiles <- grep( @@ -227,8 +232,6 @@ compareScenarios <- function( ymlthis::use_rmarkdown( newYaml, path = file.path(pathDir, "cs_main.Rmd"), - template = system.file( - "compareScenarios/cs_main.Rmd", - package = "piamPlotComparison"), + template = file.path(piamutils::getPackageLocation("piamPlotComparison"), "compareScenarios/cs_main.Rmd"), include_yaml = FALSE) } diff --git a/README.md b/README.md index a8b2d68..c32007c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Create comparison plots for your model results -R package **piamPlotComparison**, version **0.0.8** +R package **piamPlotComparison**, version **0.0.9** [![CRAN status](https://www.r-pkg.org/badges/version/piamPlotComparison)](https://cran.r-project.org/package=piamPlotComparison) [![R build status](https://github.com/pik-piam/piamPlotComparison/workflows/check/badge.svg)](https://github.com/pik-piam/piamPlotComparison/actions) [![codecov](https://codecov.io/gh/pik-piam/piamPlotComparison/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/piamPlotComparison) [![r-universe](https://pik-piam.r-universe.dev/badges/piamPlotComparison)](https://pik-piam.r-universe.dev/builds) @@ -46,7 +46,7 @@ In case of questions / problems please contact Falk Benke To cite package **piamPlotComparison** in publications use: -Benke F, Schoetz C (2024). _piamPlotComparison: Create comparison plots for your model results_. R package version 0.0.8, . +Benke F, Schoetz C (2024). _piamPlotComparison: Create comparison plots for your model results_. R package version 0.0.9, . A BibTeX entry for LaTeX users is @@ -55,7 +55,7 @@ A BibTeX entry for LaTeX users is title = {piamPlotComparison: Create comparison plots for your model results}, author = {Falk Benke and Christof Schoetz}, year = {2024}, - note = {R package version 0.0.8}, + note = {R package version 0.0.9}, url = {https://github.com/pik-piam/piamPlotComparison}, } ``` From d6f80e0e49eca51747d4d431634964e586547698 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Tue, 23 Apr 2024 14:28:00 +0200 Subject: [PATCH 2/2] replace getPackageLocation with getSystemFile --- .buildlibrary | 2 +- CITATION.cff | 2 +- DESCRIPTION | 2 +- NAMESPACE | 2 +- R/compareScenarios.R | 36 +++++++++++++++---------------- inst/compareScenarios/cs_main.Rmd | 1 - 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 6d42911..15819f5 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '178515' +ValidationKey: '178524' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 11373cc..230bcac 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -3,7 +3,7 @@ message: If you use this software, please cite it using the metadata from this f type: software title: 'piamPlotComparison: Create comparison plots for your model results' version: 0.0.9 -date-released: '2024-04-22' +date-released: '2024-04-23' abstract: A frameworks to create comparison plots for your model results. authors: - family-names: Benke diff --git a/DESCRIPTION b/DESCRIPTION index 0e2c33d..b896c16 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Type: Package Package: piamPlotComparison Title: Create comparison plots for your model results Version: 0.0.9 -Date: 2024-04-22 +Date: 2024-04-23 Authors@R: c( person("Falk", "Benke", , "benke@pik-potsdam.de", role = c("aut", "cre")), person("Christof", "Schoetz", role = "aut") diff --git a/NAMESPACE b/NAMESPACE index 2d53e39..0c5e5c4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,7 +15,7 @@ importFrom(dplyr,left_join) importFrom(dplyr,mutate) importFrom(dplyr,select) importFrom(dplyr,summarize) -importFrom(piamutils,getPackageLocation) +importFrom(piamutils,getSystemFile) importFrom(rlang,.data) importFrom(rlang,.env) importFrom(tidyr,pivot_wider) diff --git a/R/compareScenarios.R b/R/compareScenarios.R index 0516ebd..f4ac755 100644 --- a/R/compareScenarios.R +++ b/R/compareScenarios.R @@ -29,7 +29,7 @@ #' an preprocess data in your global environment during development. #' @param quiet \code{logical(1)}. Suppress printing during rendering? #' @param ... YAML parameters, see below. -#' @importFrom piamutils getPackageLocation +#' @importFrom piamutils getSystemFile #' @return The value returned by \code{\link[rmarkdown:render]{rmarkdown::render()}}. #' @section YAML Parameters: #' \describe{ @@ -125,14 +125,14 @@ #' } #' @export compareScenarios <- function( - mifScen, mifHist, - projectLibrary = NULL, - outputDir = getwd(), - outputFile = "CompareScenarios", - outputFormat = "PDF", - envir = new.env(), - quiet = FALSE, - ... + mifScen, mifHist, + projectLibrary = NULL, + outputDir = getwd(), + outputFile = "CompareScenarios", + outputFormat = "PDF", + envir = new.env(), + quiet = FALSE, + ... ) { # Set yaml parameters and convert relative to absolute paths. yamlParams <- c( @@ -163,11 +163,11 @@ compareScenarios <- function( # copy the template directory from the package to the outputDir because # rmarkdown writes to the folder containing the template. templateInOutputDir <- file.path(outputDir, "compareScenarios", "cs_main.Rmd") - file.copy(file.path(piamutils::getPackageLocation("piamPlotComparison"), "compareScenarios"), + file.copy(piamutils::getSystemFile("compareScenarios", package = "piamPlotComparison"), outputDir, recursive = TRUE) if (!is.null(projectLibrary)) { - file.copy(file.path(piamutils::getPackageLocation(projectLibrary), "compareScenarios"), + file.copy(piamutils::getSystemFile("compareScenarios", package = projectLibrary), outputDir, recursive = TRUE) } @@ -188,7 +188,7 @@ compareScenarios <- function( # Copies the CompareScenarios-Rmds to the specified location and modifies # their YAML header according to \code{yamlParams}. .compareScenarios2Rmd <- function(projectLibrary, yamlParams, outputDir, outputFile) { - pathMain <- file.path(piamutils::getPackageLocation("piamPlotComparison"), "compareScenarios/cs_main.Rmd") + pathMain <- piamutils::getSystemFile("compareScenarios/cs_main.Rmd", package = "piamPlotComparison") linesMain <- readLines(pathMain) delimiters <- grep("^(---|\\.\\.\\.)\\s*$", linesMain) headerMain <- linesMain[(delimiters[1]):(delimiters[2])] @@ -212,14 +212,10 @@ compareScenarios <- function( if (!dir.exists(pathDir)) dir.create(pathDir) - dirFiles <- dir(file.path(piamutils::getPackageLocation("piamPlotComparison"), "compareScenarios"), - full.names = TRUE) + dirFiles <- dir(piamutils::getSystemFile("compareScenarios", package = "piamPlotComparison"), full.names = TRUE) if (!is.null(projectLibrary)) { - dirFiles <- c(dirFiles, - dir(file.path(piamutils::getPackageLocation(projectLibrary), - "compareScenarios"), - full.names = TRUE)) + dirFiles <- c(dirFiles, dir(piamutils::getSystemFile("compareScenarios", package = projectLibrary), full.names = TRUE)) } rmdDirFiles <- grep( @@ -232,6 +228,8 @@ compareScenarios <- function( ymlthis::use_rmarkdown( newYaml, path = file.path(pathDir, "cs_main.Rmd"), - template = file.path(piamutils::getPackageLocation("piamPlotComparison"), "compareScenarios/cs_main.Rmd"), + template = piamutils::getSystemFile( + "compareScenarios/cs_main.Rmd", + package = "piamPlotComparison"), include_yaml = FALSE) } diff --git a/inst/compareScenarios/cs_main.Rmd b/inst/compareScenarios/cs_main.Rmd index 98c0648..9586817 100644 --- a/inst/compareScenarios/cs_main.Rmd +++ b/inst/compareScenarios/cs_main.Rmd @@ -83,7 +83,6 @@ if (interactive()) { # may cause "Undefined control sequence" errors in LaTeX. try(unloadNamespace("kableExtra"), silent = TRUE) -library(piamPlotComparison) suppressMessages(library(gridExtra)) options(tidyverse.quiet = TRUE) library(tidyverse)