Skip to content

Commit

Permalink
write.mapie flexible for time .nc variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
emolinab committed May 23, 2022
1 parent ee7cc0b commit 1f3b909
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '12021660'
ValidationKey: '12074185'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# testthat snapshots are machine-generated regression tests that
# have to be preserved exactly as they are
exclude: '^tests/testthat/_snaps/.*$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
rev: v4.2.0
hooks:
- id: check-case-conflict
- id: check-json
- id: check-yaml
- id: check-merge-conflict
- id: fix-byte-order-marker
- id: end-of-file-fixer
ci:
autoupdate_schedule: quarterly
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "magclass: Data Class and Tools for Handling Spatial-Temporal Data",
"version": "6.3.0",
"version": "6.3.1",
"description": "<p>Data class for increased interoperability working with spatial-\n temporal data together with corresponding functions and methods (conversions,\n basic calculations and basic data manipulation). The class distinguishes\n between spatial, temporal and other dimensions to facilitate the development\n and interoperability of tools build for it. Additional features are name-based\n addressing of data and internal consistency checks (e.g. checking for the right\n data order in calculations).<\/p>",
"creators": [
{
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: magclass
Type: Package
Title: Data Class and Tools for Handling Spatial-Temporal Data
Version: 6.3.0
Date: 2022-03-31
Version: 6.3.1
Date: 2022-05-23
Authors@R: c(person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = c("aut","cre")),
person("Benjamin Leon", "Bodirsky", email = "bodirsky@pik-potsdam.de", role = "aut"),
person("Markus", "Bonsch", role = "aut"),
Expand Down Expand Up @@ -49,5 +49,5 @@ BugReports: https://github.com/pik-piam/magclass/issues
License: LGPL-3 | file LICENSE
LazyData: true
Encoding: UTF-8
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
VignetteBuilder: knitr
9 changes: 6 additions & 3 deletions R/write.magpie.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#' full access for user, read access for group and no acess for anybody else).
#' Set to NULL system defaults will be used. Access codes are identical to the
#' codes used in unix function chmod.
#' @param zname Time variable for the writeRaster function
#' @param ... additional arguments passed to specific write functions
#' @note
#'
Expand Down Expand Up @@ -92,7 +93,7 @@
#' @importFrom utils write.csv write.table
#' @export
write.magpie <- function(x, file_name, file_folder = "", file_type = NULL, append = FALSE, comment = NULL, # nolint
comment.char = "*", mode = NULL, ...) { # nolint
comment.char = "*", mode = NULL, zname = NULL,...) { # nolint
umask <- Sys.umask()
if (!is.null(mode)) {
umaskMode <- as.character(777 - as.integer(mode))
Expand Down Expand Up @@ -196,9 +197,11 @@ write.magpie <- function(x, file_name, file_folder = "", file_type = NULL, appen
x <- x[[1]]
}
if (is.null(varname)) varname <- "Variable"
zname <- if(!is.null(zname)) zname else "Time"
raster::writeRaster(x, filename = filePath, format = format[file_type], overwrite = TRUE,
zname = "Time", zunit = zunit, varname = varname, ...)
zname = zname, zunit = zunit, varname = varname, ...)
} else if (file_type == "nc") {
zname <- if(!is.null(zname)) zname else "Time"
if (!requireNamespace("ncdf4", quietly = TRUE) || !requireNamespace("raster", quietly = TRUE)) {
stop("The packages \"ncdf4\" and \"raster\" are required!")
}
Expand Down Expand Up @@ -233,7 +236,7 @@ write.magpie <- function(x, file_name, file_folder = "", file_type = NULL, appen
}
}
raster::writeRaster(.sub(x, varnames[1]), filename = filePath, format = "CDF", overwrite = TRUE,
compression = 9, zname = "Time", zunit = zunit, varname = varnames[1], varunit = unit, ...)
compression = 9, zname = zname, zunit = zunit, varname = varnames[1], varunit = unit, ...)
nc <- ncdf4::nc_open(filePath, write = TRUE)
if (zunit == "years") {
try(ncdf4::ncvar_put(nc, "Time", years), silent = TRUE)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Data Class and Tools for Handling Spatial-Temporal Data

R package **magclass**, version **6.3.0**
R package **magclass**, version **6.3.1**

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

Expand Down Expand Up @@ -55,7 +55,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

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

Dietrich J, Bodirsky B, Bonsch M, Humpenoeder F, Bi S, Karstens K, Leip D (2022). _magclass: Data Class and Tools for Handling Spatial-Temporal Data_. doi: 10.5281/zenodo.1158580 (URL: https://doi.org/10.5281/zenodo.1158580), R package version 6.3.0, <URL: https://github.com/pik-piam/magclass>.
Dietrich J, Bodirsky B, Bonsch M, Humpenoeder F, Bi S, Karstens K, Leip D (2022). _magclass: Data Class and Tools for Handling Spatial-Temporal Data_. doi: 10.5281/zenodo.1158580 (URL: https://doi.org/10.5281/zenodo.1158580), R package version 6.3.1, <URL: https://github.com/pik-piam/magclass>.

A BibTeX entry for LaTeX users is

Expand All @@ -64,7 +64,7 @@ A BibTeX entry for LaTeX users is
title = {magclass: Data Class and Tools for Handling Spatial-Temporal Data},
author = {Jan Philipp Dietrich and Benjamin Leon Bodirsky and Markus Bonsch and Florian Humpenoeder and Stephen Bi and Kristine Karstens and Debbora Leip},
year = {2022},
note = {R package version 6.3.0},
note = {R package version 6.3.1},
doi = {10.5281/zenodo.1158580},
url = {https://github.com/pik-piam/magclass},
}
Expand Down
5 changes: 3 additions & 2 deletions magclass.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageCheckArgs: --as-cran
PackageRoxygenize: rd,collate,namespace,vignette
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
3 changes: 3 additions & 0 deletions man/write.magpie.Rd

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

0 comments on commit 1f3b909

Please sign in to comment.