Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
pfuehrlich-pik committed Jan 11, 2024
1 parent c1dcdf6 commit 12565f1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
7 changes: 5 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: '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
Expand All @@ -30,6 +30,9 @@ authors:
- family-names: Leip
given-names: Debbora
email: [email protected]
- family-names: Sauer
given-names: Pascal
email: [email protected]
- family-names: Baumstark
given-names: Lavinia
email: [email protected]
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre")),
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = "aut"),
Expand All @@ -11,6 +11,7 @@ Authors@R: c(
person("Stephen", "Bi", role = "aut"),
person("Kristine", "Karstens", , "[email protected]", role = "aut"),
person("Debbora", "Leip", , "[email protected]", role = "aut"),
person("Pascal", "Sauer", , "[email protected]", role = "aut"),
person("Lavinia", "Baumstark", , "[email protected]", role = "ctb"),
person("Christoph", "Bertram", , "[email protected]", role = "ctb"),
person("Anastasis", "Giannousakis", , "[email protected]", role = "ctb"),
Expand Down Expand Up @@ -52,7 +53,6 @@ Suggests:
quitte,
raster,
rmarkdown,
sf,
terra,
testthat (>= 3.1.5),
tibble,
Expand Down
50 changes: 24 additions & 26 deletions R/readMagpieOther.R
Original file line number Diff line number Diff line change
@@ -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"
}
}

Expand All @@ -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"
}
}
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 4 additions & 4 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.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)

Expand Down Expand Up @@ -56,16 +56,16 @@ 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 (2024). _magclass: Data Class and Tools for Handling Spatial-Temporal Data_. doi:10.5281/zenodo.1158580 <https://doi.org/10.5281/zenodo.1158580>, R package version 6.12.1, <https://github.com/pik-piam/magclass>.
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 <https://doi.org/10.5281/zenodo.1158580>, R package version 6.13.0, <https://github.com/pik-piam/magclass>.

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},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-readwritereport.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})

Expand Down

0 comments on commit 12565f1

Please sign in to comment.