Skip to content

Commit 7f80486

Browse files
authored
Merge pull request #56 from tscheypidi/master
- added dimCode to getSets output
2 parents 45c2c50 + d08071d commit 7f80486

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: magclass
22
Type: Package
33
Title: Data Class and Tools for Handling Spatial-Temporal Data
4-
Version: 5.6.0
4+
Version: 5.7.0
55
Date: 2019-12-09
66
Authors@R: c(person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = c("aut","cre")),
77
person("Benjamin Leon", "Bodirsky", email = "bodirsky@pik-potsdam.de", role = "aut"),
@@ -48,4 +48,4 @@ LazyData: true
4848
Encoding: UTF-8
4949
RoxygenNote: 7.0.2
5050
VignetteBuilder: knitr
51-
ValidationKey: 10213840
51+
ValidationKey: 10396230

R/getSets.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' names of the object with.
1313
#' @return Sets of the MAgPIE-object. If no information about contained sets is
1414
#' available NULL
15-
#' @author Markus Bonsch
15+
#' @author Markus Bonsch, Jan Philipp Dietrich
1616
#' @seealso \code{\link{getRegions}},
1717
#' \code{\link{getNames}},\code{\link{getYears}}, \code{\link{getCPR}},
1818
#' \code{\link{read.magpie}}, \code{\link{write.magpie}},
@@ -23,7 +23,7 @@
2323
#' getSets(a) <- c("reg","cell","t","bla","blub")
2424
#' getSets(a)
2525
#'
26-
#' getSets(a)[4] <- "BLA"
26+
#' getSets(a)["d3.1"] <- "BLA"
2727
#' getSets(a,fulldim=FALSE)
2828
#' getSets(a)
2929
#'
@@ -39,7 +39,14 @@ getSets <- function(x,fulldim=TRUE,sep=".") {
3939
return(x)
4040
}
4141
)
42-
out <- as.vector(unlist(tmp))
42+
addDimCode <- function(x) {
43+
names(x) <- 1:length(x)
44+
return(x)
45+
}
46+
tmp <- lapply(tmp,addDimCode)
47+
names(tmp) <- paste0("d",1:length(tmp))
48+
49+
out <- unlist(tmp)
4350
}
4451
return(out)
4552
}

man/getSets.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-getSets.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ context("Set Manipulation Test")
22

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

0 commit comments

Comments
 (0)