From 78bd2a74338829660ac84128f903fbb6a40a6507 Mon Sep 17 00:00:00 2001 From: Jan Philipp Dietrich Date: Tue, 8 Dec 2020 10:50:17 +0100 Subject: [PATCH] bugfix in datacol detection for data.frames --- .buildlibrary | 2 +- .zenodo.json | 2 +- DESCRIPTION | 4 ++-- R/as.magpie.R | 7 ++++++- README.md | 6 +++--- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 460932c8..36c78f99 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '95861259' +ValidationKey: '95885016' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/.zenodo.json b/.zenodo.json index bfa08054..fe41c937 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,6 +1,6 @@ { "title": "magclass: Data Class and Tools for Handling Spatial-Temporal Data", - "version": "5.15.3", + "version": "5.15.4", "description": "

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": [ { diff --git a/DESCRIPTION b/DESCRIPTION index e46ad3a8..3d6d6c52 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: magclass Type: Package Title: Data Class and Tools for Handling Spatial-Temporal Data -Version: 5.15.3 -Date: 2020-12-07 +Version: 5.15.4 +Date: 2020-12-08 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"), diff --git a/R/as.magpie.R b/R/as.magpie.R index 433272fc..f312bd16 100644 --- a/R/as.magpie.R +++ b/R/as.magpie.R @@ -193,8 +193,13 @@ setMethod("as.magpie", if(tidy) return(tidy2magpie(x,...)) if(dim(x)[1]==0) return(copy.attributes(x,new.magpie(NULL))) if(is.null(datacol)) { + is.numericlike <- function(x) { + .tmp <- function(x) return(all(!is.na(suppressWarnings(as.numeric(x[!is.na(x)]))))) + if(isFALSE(.tmp(x[1]))) return(FALSE) + return(.tmp(x)) + } for(i in dim(x)[2]:1) { - if(all(!is.na(suppressWarnings(as.numeric(x[!is.na(x[,i]),i])))) & !is.temporal(x[,i]) & !is.factor(x[,i])) { + if(!is.factor(x[[i]]) && is.numericlike(x[[i]]) && !is.temporal(x[[i]])) { datacol <- i } else { break diff --git a/README.md b/README.md index 40e8395a..0e75e862 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Data Class and Tools for Handling Spatial-Temporal Data -R package **magclass**, version **5.15.3** +R package **magclass**, version **5.15.4** [![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) @@ -55,7 +55,7 @@ In case of questions / problems please contact Jan Philipp Dietrich . A BibTeX entry for LaTeX users is @@ -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.3}, + note = {R package version 5.15.4}, doi = {10.5281/zenodo.1158580}, url = {https://github.com/pik-piam/magclass}, }