Skip to content

Commit

Permalink
Merge pull request #56 from tscheypidi/master
Browse files Browse the repository at this point in the history
- added dimCode to getSets output
  • Loading branch information
tscheypidi authored Dec 9, 2019
2 parents 45c2c50 + d08071d commit 7f80486
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: magclass
Type: Package
Title: Data Class and Tools for Handling Spatial-Temporal Data
Version: 5.6.0
Version: 5.7.0
Date: 2019-12-09
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"),
Expand Down Expand Up @@ -48,4 +48,4 @@ LazyData: true
Encoding: UTF-8
RoxygenNote: 7.0.2
VignetteBuilder: knitr
ValidationKey: 10213840
ValidationKey: 10396230
13 changes: 10 additions & 3 deletions R/getSets.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' names of the object with.
#' @return Sets of the MAgPIE-object. If no information about contained sets is
#' available NULL
#' @author Markus Bonsch
#' @author Markus Bonsch, Jan Philipp Dietrich
#' @seealso \code{\link{getRegions}},
#' \code{\link{getNames}},\code{\link{getYears}}, \code{\link{getCPR}},
#' \code{\link{read.magpie}}, \code{\link{write.magpie}},
Expand All @@ -23,7 +23,7 @@
#' getSets(a) <- c("reg","cell","t","bla","blub")
#' getSets(a)
#'
#' getSets(a)[4] <- "BLA"
#' getSets(a)["d3.1"] <- "BLA"
#' getSets(a,fulldim=FALSE)
#' getSets(a)
#'
Expand All @@ -39,7 +39,14 @@ getSets <- function(x,fulldim=TRUE,sep=".") {
return(x)
}
)
out <- as.vector(unlist(tmp))
addDimCode <- function(x) {
names(x) <- 1:length(x)
return(x)
}
tmp <- lapply(tmp,addDimCode)
names(tmp) <- paste0("d",1:length(tmp))

out <- unlist(tmp)
}
return(out)
}
Expand Down
4 changes: 2 additions & 2 deletions man/getSets.Rd

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

6 changes: 4 additions & 2 deletions tests/testthat/test-getSets.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ context("Set Manipulation Test")

test_that("sets names can be overwritten", {
x <- new.magpie("GLO.REG","y1995","BLA.BLUB",sets=c("glo.reg","year","glo.data"))
expect_identical(getSets(x),c("glo","reg","year","glo","data"))
expect_identical(getSets(x),c("d1.1"="glo","d1.2"="reg","d2.1"="year","d3.1"="glo","d3.2"="data"))
getSets(x)[4] <- "bla"
expect_identical(getSets(x),c("glo","reg","year","bla","data"))
expect_identical(getSets(x),c("d1.1"="glo","d1.2"="reg","d2.1"="year","d3.1"="bla","d3.2"="data"))
getSets(x)["d1.2"] <- "region"
expect_identical(getSets(x),c("d1.1"="glo","d1.2"="region","d2.1"="year","d3.1"="bla","d3.2"="data"))
})

0 comments on commit 7f80486

Please sign in to comment.