Skip to content

Commit

Permalink
Merge branch 'fix_fmt_check_runner' into 'master'
Browse files Browse the repository at this point in the history
Fix fmt check runner

See merge request lpjml/lpjmlkit!92
  • Loading branch information
stephnwirth committed Mar 25, 2024
2 parents c9e4cbc + 09e7b0d commit d1cdf36
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '2613204'
ValidationKey: '2634331'
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: 'lpjmlkit: Toolkit for Basic LPJmL Handling'
version: 1.3.2
date-released: '2024-03-15'
version: 1.3.3
date-released: '2024-03-25'
abstract: A collection of basic functions to facilitate the work with the Dynamic
Global Vegetation Model (DGVM) Lund-Potsdam-Jena managed Land (LPJmL) hosted at
the Potsdam Institute for Climate Impact Research (PIK). It provides functions for
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: lpjmlkit
Type: Package
Title: Toolkit for Basic LPJmL Handling
Version: 1.3.2
Version: 1.3.3
Authors@R: c(
person("Jannes", "Breier", , "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9055-6904")),
person("Sebastian","Ostberg", , "[email protected]", role = "aut", comment = c(ORCID = "0000-0002-2368-7015")),
Expand Down Expand Up @@ -54,4 +54,4 @@ Suggests:
sf
Config/testthat/edition: 3
VignetteBuilder: knitr
Date: 2024-03-15
Date: 2024-03-25
83 changes: 57 additions & 26 deletions R/write_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#' Requires a \link[tibble]{tibble} (modern \link[base]{data.frame} class) in a
#' specific format (see details & examples) to write the model configuration
#' file `"config_*.json"`. Each row in the tibble corresponds to a model run.
#' The generated `"config_*.json"` is based on a js file (e.g. `"lpjml_*.js"`).
#' The generated `"config_*.json"` is based on a cjson file
#' (e.g. `"lpjml_config.cjson"`).
#'
#' @param x A tibble in a defined format (see details).
#'
Expand All @@ -26,8 +27,8 @@
#' individually. Choose between `"annual"`, `"monthly"` or `"daily"`.
#'
#' @param output_format Character string defining the format of the output.
#' Defaults to `"raw"`. Further options: `"cdf"` (NetCDF) or `"clm"`
#' (file with header).
#' Defaults to `NULL` (use default from cjson file). Options: `"raw"`,
#' `"cdf"` (NetCDF) or `"clm"` (file with header).
#'
#' @param cjson_filename Character string providing the name of the main LPJmL
#' configuration file to be parsed. Defaults to `"lpjml_config.cjson"`.
Expand Down Expand Up @@ -268,7 +269,7 @@ write_config <- function(x,
sim_path = NULL,
output_list = c(),
output_list_timestep = "annual",
output_format = "raw",
output_format = NULL,
cjson_filename = "lpjml_config.cjson",
parallel_cores = 4,
debug = FALSE,
Expand Down Expand Up @@ -622,10 +623,29 @@ mutate_config_output <- function(x, # nolint:cyclocomp_linter.
for (x_id in seq_len(length(x[["output"]]))) {

# Replace output format in x if defined (e.g. raw, clm, cdf)
if (x[["output"]][[x_id]]$file$fmt != "txt") {
if (!is.null(output_format) &&
(is.null(x[["output"]][[x_id]]$file$fmt) ||
x[["output"]][[x_id]]$file$fmt != "txt")) {
x[["output"]][[x_id]]$file$fmt <- output_format
}

# make it backwards compatible for old way of explicitly mentioning the
# file extension in the output file name
if (!is.null(output_format) && is.null(x[["default_fmt"]])) {
new_ext <- switch(
output_format,
raw = ".bin",
clm = ".clm",
cdf = ".nc4"
)
# Replace file extension of file name in output
x[["output"]][[x_id]]$file$name <- sub(
"\\.[^.]+$",
new_ext,
x[["output"]][[x_id]]$file$name
)
}

# Replace output path in x
x[["output"]][[x_id]]$file$name <- gsub("output/",
opath,
Expand All @@ -641,7 +661,7 @@ mutate_config_output <- function(x, # nolint:cyclocomp_linter.
# Empty output and include grid if not done
x["output"] <- list(c())

if (!("grid" %in% output_list) && !("cdf" %in% output_format)) {
if (!("grid" %in% output_list)) {
output_list <- append(output_list, "grid", after = 0)
output_timestep <- append(output_timestep, NA, after = 0)

Expand All @@ -666,17 +686,19 @@ mutate_config_output <- function(x, # nolint:cyclocomp_linter.
new_output[["id"]] <- output_list[id_ov]
new_output[["file"]] <- list()

# Output format three possibilities: netcdf: cdf, raw: bin and clm
new_output[["file"]][["fmt"]] <- ifelse(
length(output_format) == 1 && is.character(output_format),
ifelse(output_list[id_ov] == "globalflux", "txt", output_format),
stop(
"No valid output_format. Please choose in from \"raw\"",
" \"clm\" or \"cdf\" in form of a single character ",
"string."
)
)

if (!is.null(output_format)) {
# Output format three possibilities: netcdf: cdf, raw: bin and clm
new_output[["file"]][["fmt"]] <- ifelse(
length(output_format) == 1 && is.character(output_format),
ifelse(output_list[id_ov] == "globalflux", "txt", output_format),
stop(
"No valid output_format. Please choose in from \"raw\"",
" \"clm\" or \"cdf\" in form of a single character ",
"string."
)
)
}
# Output_timestep could be supplied as a single character string
# prescribing a timestep for all outputs or as a character vector
# with the length of output_list to assign an individual timestep for
Expand Down Expand Up @@ -738,17 +760,26 @@ mutate_config_output <- function(x, # nolint:cyclocomp_linter.

# Create file name with correct path, corresponding outputvar name and
# file extension based on the output_format
new_output[["file"]][["name"]] <- paste0(
opath,
output_list[id_ov], ".",
ifelse(output_list[id_ov] == "globalflux",
"txt",
switch(output_format,
raw = "bin",
clm = "clm",
cdf = "nc4")
# make it backwards compatible for old way of explicitly mentioning the
# file extension in the output file name
if (!is.null(output_format) && is.null(x[["default_fmt"]])) {
new_output[["file"]][["name"]] <- paste0(
opath,
output_list[id_ov], ".",
ifelse(output_list[id_ov] == "globalflux",
"txt",
switch(output_format,
raw = "bin",
clm = "clm",
cdf = "nc4")
)
)
)
} else {
new_output[["file"]][["name"]] <- paste0(
opath,
output_list[id_ov]
)
}

# Append new output to output in config
x[["output"]] <- append(x[["output"]], list(new_output))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Toolkit for Basic LPJmL Handling <a href=''><img src='inst/img/logo.png' align='right' height='139' /></a>

R package **lpjmlkit**, version **1.3.2**
R package **lpjmlkit**, version **1.3.3**

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

Expand Down Expand Up @@ -76,7 +76,7 @@ In case of questions / problems please contact Jannes Breier <jannesbr@pik-potsd

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

Breier J, Ostberg S, Wirth S, Minoli S, Stenzel F, Müller C (2024). _lpjmlkit: Toolkit for Basic LPJmL Handling_. doi: 10.5281/zenodo.7773134 (URL: https://doi.org/10.5281/zenodo.7773134), R package version 1.3.2, <URL: https://github.com/PIK-LPJmL/lpjmlkit>.
Breier J, Ostberg S, Wirth S, Minoli S, Stenzel F, Müller C (2024). _lpjmlkit: Toolkit for Basic LPJmL Handling_. doi: 10.5281/zenodo.7773134 (URL: https://doi.org/10.5281/zenodo.7773134), R package version 1.3.3, <URL: https://github.com/PIK-LPJmL/lpjmlkit>.

A BibTeX entry for LaTeX users is

Expand All @@ -85,7 +85,7 @@ A BibTeX entry for LaTeX users is
title = {lpjmlkit: Toolkit for Basic LPJmL Handling},
author = {Jannes Breier and Sebastian Ostberg and Stephen Björn Wirth and Sara Minoli and Fabian Stenzel and Christoph Müller},
year = {2024},
note = {R package version 1.3.2},
note = {R package version 1.3.3},
doi = {10.5281/zenodo.7773134},
url = {https://github.com/PIK-LPJmL/lpjmlkit},
}
Expand Down
9 changes: 5 additions & 4 deletions man/write_config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/testthat/test-write_config.R
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ test_that("include non output defined outputvars", {
length(tmp_objects[[1]][["output"]])
]]$file$name)
)

})


Expand Down

0 comments on commit d1cdf36

Please sign in to comment.