From 12565f1c1c89f743e9b2c517a8ad6ebba44375bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20F=C3=BChrlich?= Date: Thu, 11 Jan 2024 16:01:43 +0100 Subject: [PATCH] build --- .buildlibrary | 2 +- CITATION.cff | 7 ++-- DESCRIPTION | 6 ++-- R/readMagpieOther.R | 50 +++++++++++++-------------- README.md | 8 ++--- tests/testthat/test-readwritereport.R | 2 +- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 48275a45..40695694 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '120779572' +ValidationKey: '120963290' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index e7d3ab05..b1c2f2e0 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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: 'magclass: Data Class and Tools for Handling Spatial-Temporal Data' -version: 6.12.1 -date-released: '2024-01-10' +version: 6.13.0 +date-released: '2024-01-11' abstract: Data class for increased interoperability working with spatial-temporal data together with corresponding functions and methods (conversions, basic calculations and basic data manipulation). The class distinguishes between spatial, temporal @@ -30,6 +30,9 @@ authors: - family-names: Leip given-names: Debbora email: leip@pik-potsdam.de +- family-names: Sauer + given-names: Pascal + email: pascal.sauer@pik-potsdam.de - family-names: Baumstark given-names: Lavinia email: lavinia@pik-potsdam.de diff --git a/DESCRIPTION b/DESCRIPTION index c89d061f..5617db39 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: magclass Title: Data Class and Tools for Handling Spatial-Temporal Data -Version: 6.12.1 -Date: 2024-01-10 +Version: 6.13.0 +Date: 2024-01-11 Authors@R: c( person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = c("aut", "cre")), person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = "aut"), @@ -11,6 +11,7 @@ Authors@R: c( person("Stephen", "Bi", role = "aut"), person("Kristine", "Karstens", , "karstens@pik-potsdam.de", role = "aut"), person("Debbora", "Leip", , "leip@pik-potsdam.de", role = "aut"), + person("Pascal", "Sauer", , "pascal.sauer@pik-potsdam.de", role = "aut"), person("Lavinia", "Baumstark", , "lavinia@pik-potsdam.de", role = "ctb"), person("Christoph", "Bertram", , "bertram@pik-potsdam.de", role = "ctb"), person("Anastasis", "Giannousakis", , "giannou@pik-potsdam.de", role = "ctb"), @@ -52,7 +53,6 @@ Suggests: quitte, raster, rmarkdown, - sf, terra, testthat (>= 3.1.5), tibble, diff --git a/R/readMagpieOther.R b/R/readMagpieOther.R index adca5345..5c746af5 100644 --- a/R/readMagpieOther.R +++ b/R/readMagpieOther.R @@ -1,35 +1,33 @@ - readMagpieOther <- function(fileName, fileType, comment.char = "*", check.names = FALSE) { # nolint - sep <- ifelse(fileType == "put", "\t", ",") # check for header - temp <- read.csv(fileName, nrow = 1, header = FALSE, sep = sep, comment.char = comment.char, - check.names = check.names, stringsAsFactors = TRUE) + temp <- utils::read.csv(fileName, nrow = 1, header = FALSE, sep = sep, comment.char = comment.char, + check.names = check.names, stringsAsFactors = TRUE) # check for numeric elements in first row, which means a missing header header <- !any(sapply(temp, is.numeric)) #nolint - temp <- read.csv(fileName, header = header, sep = sep, comment.char = comment.char, - check.names = check.names, stringsAsFactors = TRUE) + temp <- utils::read.csv(fileName, header = header, sep = sep, comment.char = comment.char, + check.names = check.names, stringsAsFactors = TRUE) # analyse column content coltypes <- rep("data", dim(temp)[2]) - for (column in 1:dim(temp)[2]) { - if (sum(coltypes == "year") == 0 & - length(grep("^(y[0-9]{4}|[0-2][0-9]{3})$", temp[, column])) == dim(temp)[1]) { + for (column in seq_len(dim(temp)[2])) { + if (sum(coltypes == "year") == 0 && + length(grep("^(y[0-9]{4}|[0-2][0-9]{3})$", temp[, column])) == dim(temp)[1]) { coltypes[column] <- "year" - } else if (sum(coltypes == "region") == 0 & sum(coltypes == "regiospatial") == 0 & - length(grep("^[A-Z]{3}$", temp[, column])) == dim(temp)[1]) { + } else if (sum(coltypes == "region") == 0 && sum(coltypes == "regiospatial") == 0 && + length(grep("^[A-Z]{3}$", temp[, column])) == dim(temp)[1]) { coltypes[column] <- "region" - } else if (sum(coltypes == "regiospatial") == 0 & sum(coltypes == "region") == 0 & - length(grep("^[A-Z]{3}_[0-9]+$", temp[, column])) == dim(temp)[1]) { + } else if (sum(coltypes == "regiospatial") == 0 && sum(coltypes == "region") == 0 && + length(grep("^[A-Z]{3}_[0-9]+$", temp[, column])) == dim(temp)[1]) { coltypes[column] <- "regiospatial" } else if (!is.numeric(temp[1, column])) { coltypes[column] <- "other" } else if (sum(coltypes == "cell") == 0 && all(!is.na(temp[, column])) && all(temp[, column] != 0) && - length(temp[, column]) %% max(temp[, column]) == 0 && - suppressWarnings(try(all(unique(temp[, column]) == 1:max(temp[, column])), silent = TRUE) == TRUE)) { - coltypes[column] <- "cell" + length(temp[, column]) %% max(temp[, column]) == 0 && + suppressWarnings(try(all(unique(temp[, column]) == 1:max(temp[, column])), silent = TRUE) == TRUE)) { + coltypes[column] <- "cell" } } @@ -45,9 +43,9 @@ readMagpieOther <- function(fileName, fileType, comment.char = "*", check.names if (dimnames(temp)[[2]][which(coltypes == "cell")] == "iteration") { temp[, which(coltypes == "cell")] <- paste("iter", format(temp[, which(coltypes == "cell")]), sep = "") coltypes[which(coltypes == "cell")] <- "other" - } else if (header & !(dimnames(temp)[[2]][which(coltypes == "cell")] %in% - c("dummy", "dummy.1", "dummy.2", "dummy.3", "", " ", - "cell", "cells", "Cell", "Cells"))) { + } else if (header && !(dimnames(temp)[[2]][which(coltypes == "cell")] %in% + c("dummy", "dummy.1", "dummy.2", "dummy.3", "", " ", + "cell", "cells", "Cell", "Cells"))) { coltypes[which(coltypes == "cell")] <- "data" } } @@ -165,29 +163,29 @@ readMagpieOther <- function(fileName, fileType, comment.char = "*", check.names dimnames(output)[[2]] <- yearnames dimnames(output)[[3]] <- elemnames - if (any(coltypes == "other") & (headertype == "other" | headertype == "none")) { + if (any(coltypes == "other") && (headertype == "other" || headertype == "none")) { counter <- 0 for (other.elem in othernames) { output[, , (1:sum(coltypes == "data")) + counter] <- array(as.vector( - as.matrix(temp[which(temp[, which(coltypes == "other")] == other.elem), - which(coltypes == "data")])), c(ncells, nyears, sum(coltypes == "data"))) + as.matrix(temp[which(temp[, which(coltypes == "other")] == other.elem), which(coltypes == "data")]) + ), c(ncells, nyears, sum(coltypes == "data"))) counter <- counter + sum(coltypes == "data") } - } else if (!any(coltypes == "other") & headertype == "region") { + } else if (!any(coltypes == "other") && headertype == "region") { for (i in seq_along(cellnames)) { output[i, , 1] <- temp[, which(coltypes == "data")[i]] } - } else if (!any(coltypes == "other") & headertype == "year") { + } else if (!any(coltypes == "other") && headertype == "year") { for (year in yearnames) { output[, year, 1] <- temp[, year] } - } else if (any(coltypes == "other") & headertype == "region") { + } else if (any(coltypes == "other") && headertype == "region") { for (i in seq_along(cellnames)) { for (elem in elemnames) { output[i, , elem] <- temp[which(temp[, which(coltypes == "other")] == elem), which(coltypes == "data")[i]] } } - } else if (any(coltypes == "other") & headertype == "year") { + } else if (any(coltypes == "other") && headertype == "year") { for (year in yearnames) { for (elem in elemnames) { output[, year, elem] <- temp[which(temp[, which(coltypes == "other")] == elem), year] diff --git a/README.md b/README.md index 282c0449..165decb9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Data Class and Tools for Handling Spatial-Temporal Data -R package **magclass**, version **6.12.1** +R package **magclass**, version **6.13.0** [![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/builds) @@ -56,16 +56,16 @@ In case of questions / problems please contact Jan Philipp Dietrich , R package version 6.12.1, . +Dietrich J, Bodirsky B, Bonsch M, Humpenoeder F, Bi S, Karstens K, Leip D, Sauer P (2024). _magclass: Data Class and Tools for Handling Spatial-Temporal Data_. doi:10.5281/zenodo.1158580 , R package version 6.13.0, . A BibTeX entry for LaTeX users is ```latex @Manual{, 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}, + author = {Jan Philipp Dietrich and Benjamin Leon Bodirsky and Markus Bonsch and Florian Humpenoeder and Stephen Bi and Kristine Karstens and Debbora Leip and Pascal Sauer}, year = {2024}, - note = {R package version 6.12.1}, + note = {R package version 6.13.0}, url = {https://github.com/pik-piam/magclass}, doi = {10.5281/zenodo.1158580}, } diff --git a/tests/testthat/test-readwritereport.R b/tests/testthat/test-readwritereport.R index 6c32450d..88e58f37 100644 --- a/tests/testthat/test-readwritereport.R +++ b/tests/testthat/test-readwritereport.R @@ -109,7 +109,7 @@ test_that("read/write report works with braces", { fill = 0) foo["DEU", 2020, "Emissions|CO2|Energy|Demand|Transportation (w/ bunkers) (Mt CO2/yr)"] <- 10 expect_silent(write.report(foo, f)) - df <- read.csv(f, sep = ";", stringsAsFactors = FALSE) + df <- utils::read.csv(f, sep = ";", stringsAsFactors = FALSE) expect_identical(df$Unit, "Mt CO2/yr") })