Skip to content

Commit

Permalink
rownames sometimes got lost during filtering in as.magpie
Browse files Browse the repository at this point in the history
  • Loading branch information
tscheypidi committed Dec 10, 2020
1 parent d916763 commit 7676c75
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '95885016'
ValidationKey: '95913930'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
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": "5.15.4",
"version": "5.15.5",
"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
4 changes: 2 additions & 2 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: 5.15.4
Date: 2020-12-08
Version: 5.15.5
Date: 2020-12-10
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
41 changes: 22 additions & 19 deletions R/as.magpie.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@ setGeneric("as.magpie", function(x,...)standardGeneric("as.magpie"))

setMethod("as.magpie",signature(x = "magpie"),function (x) return(x))

tmpfilter <- function(x, sep=".", replacement="_") {
.tmp <- function(x, sep, replacement) {
if(sep!=replacement) x <- gsub(sep, replacement, x, fixed = TRUE, useBytes = TRUE)
x[x==""] <- " "

tmpfilter <- function(x,sep=".", replacement="_") {
.tmpfilter <- function(x, sep=".", replacement="_") {
.tmp <- function(x, sep, replacement) {
if(sep!=replacement) x <- gsub(sep, replacement, x, fixed = TRUE, useBytes = TRUE)
x[x==""] <- " "
return(x)
}
if(is.factor(x)) {
levels(x) <- .tmp(levels(x), sep, replacement)
} else if(is.character(x)) {
x <- .tmp(x, sep, replacement)
}
return(x)
}
if(is.factor(x)) {
levels(x) <- .tmp(levels(x), sep, replacement)
} else if(is.character(x)) {
x <- .tmp(x, sep, replacement)
}
cl <- class(x)
cn <- colnames(x)
rn <- rownames(x)
x <- as.data.frame(lapply(x, .tmpfilter, sep=sep, replacement=replacement))
colnames(x) <- cn
rownames(x) <- rn
class(x) <- cl
return(x)
}

Expand Down Expand Up @@ -183,11 +194,7 @@ setMethod("as.magpie",
{
# filter illegal characters
if(isTRUE(filter)) {
cl <- class(x)
cn <- colnames(x)
x <- as.data.frame(lapply(x, tmpfilter, sep=sep, replacement=replacement))
colnames(x) <- cn
class(x) <- cl
x <- tmpfilter(x, sep=sep, replacement=replacement)
}

if(tidy) return(tidy2magpie(x,...))
Expand Down Expand Up @@ -267,11 +274,7 @@ setMethod("as.magpie",
# filter illegal characters

if(isTRUE(filter)) {
cl <- class(x)
cn <- colnames(x)
x <- as.data.frame(lapply(x, tmpfilter, sep=sep, replacement=replacement))
colnames(x) <- cn
class(x) <- cl
x <- tmpfilter(x, sep=sep, replacement=replacement)
}

if(length(grep("^cell$",names(x),ignore.case=TRUE)) > 0) {
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 **5.15.4**
R package **magclass**, version **5.15.5**

[![Travis build status](https://travis-ci.com/pik-piam/magclass.svg?branch=master)](https://travis-ci.com/pik-piam/magclass) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158580.svg)](https://doi.org/10.5281/zenodo.1158580) [![codecov](https://codecov.io/gh/pik-piam/magclass/branch/master/graph/badge.svg)](https://codecov.io/gh/pik-piam/magclass)

Expand Down Expand Up @@ -55,8 +55,8 @@ 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 (2020). _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 5.15.4,
<URL: https://github.com/pik-piam/magclass>.
Spatial-Temporal Data_. doi: 10.5281/zenodo.1158580 (URL: https://doi.org/10.5281/zenodo.1158580), R package version 5.15.5, <URL:
https://github.com/pik-piam/magclass>.

A BibTeX entry for LaTeX users is

Expand All @@ -65,7 +65,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},
year = {2020},
note = {R package version 5.15.4},
note = {R package version 5.15.5},
doi = {10.5281/zenodo.1158580},
url = {https://github.com/pik-piam/magclass},
}
Expand Down
4 changes: 2 additions & 2 deletions man/replace_non_finite.Rd

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

0 comments on commit 7676c75

Please sign in to comment.