From d6f80e0e49eca51747d4d431634964e586547698 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Tue, 23 Apr 2024 14:28:00 +0200 Subject: [PATCH] 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)