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

improve file handling #11

Merged
merged 4 commits into from
May 24, 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
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '555688'
ValidationKey: '576143'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand All @@ -8,5 +8,6 @@ AcceptedNotes:
- no visible binding for global variable
- Found the following hidden files and directories: ~
- All declared Imports should be used.
- Non-standard file/directory found at top level: output
allowLinterWarnings: yes
enforceVersionUpdate: no
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: 'piamValidation: Validation Tools for PIK-PIAM'
version: 0.2.8
date-released: '2024-05-03'
version: 0.2.9
date-released: '2024-05-24'
abstract: The piamValidation package provides validation tools for the Potsdam Integrated
Assessment Modelling environment.
authors:
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: piamValidation
Title: Validation Tools for PIK-PIAM
Version: 0.2.8
Date: 2024-05-03
Version: 0.2.9
Date: 2024-05-24
Authors@R:
c(person("Pascal", "Weigmann",, "pascal.weigmann@pik-potsdam.de", role = c("aut", "cre")),
person("Oliver", "Richters",, role = "aut"))
Expand All @@ -16,6 +16,7 @@ Imports:
ggthemes,
htmltools,
knitr,
piamutils,
plotly,
quitte (>= 0.3123.0),
readxl,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import(ggplot2)
importFrom(dplyr,"%>%")
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,lag)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(ggthemes,theme_tufte)
importFrom(piamutils,getSystemFile)
importFrom(plotly,ggplotly)
importFrom(readxl,excel_sheets)
importFrom(readxl,read_excel)
Expand Down
2 changes: 1 addition & 1 deletion R/combineData.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ combineData <- function(data, cfgRow, histData = NULL) {
all_reg <- unique(data$region)
all_per <- unique(data$period) # not a factor, convert?
all_per <- all_per[all_per <= 2100]
# TODO: take ref_per from ref_data for current var
# TODO: check if this works well
ref_per <- c(2005, 2010, 2015, 2020)


Expand Down
3 changes: 2 additions & 1 deletion R/importFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ getConfig <- function(configName) {
path <- normalizePath(configName)
}
if (path == "") stop("Config not found, please provide either full path to a
config file or choose a config from 'inst/config'.")
config file or select a config from 'inst/config' by choosing its
name ('validationConfig_<name>.csv'.\n")

# config can be .xlsx or .csv, use "config" sheet in .xlsx if available
if (grepl("\\.xlsx$", path)) {
Expand Down
47 changes: 35 additions & 12 deletions R/validationReport.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,59 @@
#'
#' @param dataPath one or multiple path(s) to scenario data in .mif or .csv
#' format
#' @param config name of a config from inst/config
#' @param report specify which .Rmd file should be used to create report
#' @param config name a config from inst/config ("validationConfig_<name>.csv")
#' or give a full path to a separate configuration file
#' @param report name a .Rmd from inst/markdown ("validationReport_<name>.Rmd")
#' to be rendered or give a full path to a separate .Rmd file
#'
#' @importFrom piamutils getSystemFile
#'
#' @export

validationReport <- function(dataPath, config, report = "default") {


# convert relative to absolute paths
dataPath <- normalizePath(dataPath)

# for config only if no config in inst/config was chosen
# user has the option to enter name of files that are shipped with package
# or provide full paths to manually created files for config and report

if (file.exists(normalizePath(config, mustWork = F))) {
# full path to config given
config <- normalizePath(config)
config_name <- "Custom"
} else {
# name of config file in inst/config given
config_name <- config
}

yamlParams <- list(mif = dataPath, cfg = config)

report_name <- paste0("validation_", report)
if (file.exists(normalizePath(report, mustWork = F))) {
# full path to report given
report_path <- normalizePath(report)
report_name <- "Custom"
} else {
# name of report file in inst/markdown given
report_path <- piamutils::getSystemFile(
paste0("markdown/validationReport_", report, ".Rmd"),
package = "piamValidation")
report_name <- report
}

# put rendered reports in output folder in working directory
output_path <- paste0(getwd(), "/output")
if (!dir.exists(output_path)) dir.create(output_path)

# create default report for given data
rmarkdown::render(paste0(path.package("piamValidation"),
"/markdown/", report_name, ".Rmd"),
# include chosen config and report name in output file except if it is default
infix <- ""
if (config_name != "default") infix <- paste0(infix, "_cfg", config_name)
if (report_name != "default") infix <- paste0(infix, "_rep", report_name)

# create specified report for given data and config
yamlParams <- list(mif = dataPath, cfg = config)
rmarkdown::render(input = report_path,
params = yamlParams,
output_file = paste0(output_path, "/", report_name,
output_file = paste0(output_path, "/validation", infix,
format(Sys.time(), "_%Y%m%d-%H%M%S"),
".html"))

}

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Validation Tools for PIK-PIAM

R package **piamValidation**, version **0.2.8**
R package **piamValidation**, version **0.2.9**

[![CRAN status](https://www.r-pkg.org/badges/version/piamValidation)](https://cran.r-project.org/package=piamValidation) [![R build status](https://github.com/pik-piam/piamValidation/workflows/check/badge.svg)](https://github.com/pik-piam/piamValidation/actions) [![codecov](https://codecov.io/gh/pik-piam/piamValidation/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/piamValidation) [![r-universe](https://pik-piam.r-universe.dev/badges/piamValidation)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -46,7 +46,7 @@ In case of questions / problems please contact Pascal Weigmann <pascal.weigmann@

To cite package **piamValidation** in publications use:

Weigmann P, Richters O (2024). _piamValidation: Validation Tools for PIK-PIAM_. R package version 0.2.8, <URL: https://github.com/pik-piam/piamValidation>.
Weigmann P, Richters O (2024). _piamValidation: Validation Tools for PIK-PIAM_. R package version 0.2.9, <https://github.com/pik-piam/piamValidation>.

A BibTeX entry for LaTeX users is

Expand All @@ -55,7 +55,7 @@ A BibTeX entry for LaTeX users is
title = {piamValidation: Validation Tools for PIK-PIAM},
author = {Pascal Weigmann and Oliver Richters},
year = {2024},
note = {R package version 0.2.8},
note = {R package version 0.2.9},
url = {https://github.com/pik-piam/piamValidation},
}
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "piamValidation: COMMITTED"
title: "piamValidation: NGFS"
date: "`r format(Sys.Date())`"
output:
html_document:
Expand Down Expand Up @@ -32,12 +32,25 @@ knitr::opts_chunk$set(

## Import and Prepare Data

Loading data from:

```{r}
for (m in params$mif) cat(paste0(normalizePath(m), "\n"))
```

Using config:

```{r}
cat(params$cfg, "\n")
```


```{r, message = FALSE}
# Data Preparation
df <- validateScenarios(params$mif, params$cfg)
df <- appendTooltips(df)
```

## Validation

### Summary
Expand Down
108 changes: 0 additions & 108 deletions inst/markdown/validation_ARIADNE.Rmd

This file was deleted.

Loading