Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make copying files more robust #7

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '158648'
ValidationKey: '178524'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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-23'
abstract: A frameworks to create comparison plots for your model results.
authors:
- family-names: Benke
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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-23
Authors@R: c(
person("Falk", "Benke", , "[email protected]", role = c("aut", "cre")),
person("Christof", "Schoetz", role = "aut")
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(dplyr,summarize)
importFrom(piamutils,getSystemFile)
importFrom(rlang,.data)
importFrom(rlang,.env)
importFrom(tidyr,pivot_wider)
29 changes: 15 additions & 14 deletions R/compareScenarios.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 getSystemFile
#' @return The value returned by \code{\link[rmarkdown:render]{rmarkdown::render()}}.
#' @section YAML Parameters:
#' \describe{
Expand Down Expand Up @@ -124,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 @@ -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(piamutils::getSystemFile("compareScenarios", package = "piamPlotComparison"),
outputDir, recursive = TRUE)

if (!is.null(projectLibrary)) {
file.copy(system.file("compareScenarios", package = projectLibrary),
file.copy(piamutils::getSystemFile("compareScenarios", package = projectLibrary),
outputDir, recursive = TRUE)
}

Expand All @@ -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 <- piamutils::getSystemFile("compareScenarios/cs_main.Rmd", package = "piamPlotComparison")
linesMain <- readLines(pathMain)
delimiters <- grep("^(---|\\.\\.\\.)\\s*$", linesMain)
headerMain <- linesMain[(delimiters[1]):(delimiters[2])]
Expand All @@ -211,10 +212,10 @@ compareScenarios <- function(

if (!dir.exists(pathDir)) dir.create(pathDir)

dirFiles <- dir(system.file("compareScenarios", package = "piamPlotComparison"), full.names = TRUE)
dirFiles <- dir(piamutils::getSystemFile("compareScenarios", package = "piamPlotComparison"), full.names = TRUE)

if (!is.null(projectLibrary)) {
dirFiles <- c(dirFiles, dir(system.file("compareScenarios", package = projectLibrary), full.names = TRUE))
dirFiles <- c(dirFiles, dir(piamutils::getSystemFile("compareScenarios", package = projectLibrary), full.names = TRUE))
}

rmdDirFiles <- grep(
Expand All @@ -227,7 +228,7 @@ compareScenarios <- function(
ymlthis::use_rmarkdown(
newYaml,
path = file.path(pathDir, "cs_main.Rmd"),
template = system.file(
template = piamutils::getSystemFile(
"compareScenarios/cs_main.Rmd",
package = "piamPlotComparison"),
include_yaml = FALSE)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -46,7 +46,7 @@ In case of questions / problems please contact Falk Benke <[email protected]>

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, <https://github.com/pik-piam/piamPlotComparison>.
Benke F, Schoetz C (2024). _piamPlotComparison: Create comparison plots for your model results_. R package version 0.0.9, <https://github.com/pik-piam/piamPlotComparison>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
```
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