Skip to content

Commit

Permalink
replace getPackageLocation with getSystemFile
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Apr 23, 2024
1 parent d805b73 commit d6f80e0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '178515'
ValidationKey: '178524'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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", , "[email protected]", role = c("aut", "cre")),
person("Christof", "Schoetz", role = "aut")
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
36 changes: 17 additions & 19 deletions R/compareScenarios.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}

Expand All @@ -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])]
Expand All @@ -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(
Expand All @@ -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)
}
1 change: 0 additions & 1 deletion inst/compareScenarios/cs_main.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d6f80e0

Please sign in to comment.