Skip to content

Commit

Permalink
- as.RasterBrick fix for multi-layer objects
Browse files Browse the repository at this point in the history
- ifelse fix (hopefully) fixing exotic test failures on windows systems
  • Loading branch information
tscheypidi committed Sep 29, 2021
1 parent 014596d commit 12a00e5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
This package was submitted to CRAN on 2021-02-24.
Once it is accepted, delete this file and tag the release (commit a642ba8).
This package was submitted to CRAN on 2021-09-28.
Once it is accepted, delete this file and tag the release (commit 014596d).
7 changes: 4 additions & 3 deletions R/as.RasterBrick.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ as.RasterBrick <- function(x, res = NULL) { # nolint
xy <- getCoords(x)
if (is.null(res)) res <- .guessRes(xy)
out <- raster::brick(ncols = 360 / res, nrows = 180 / res, nl = nyears(x) * ndata(x))
m <- wrap(x, list(1, 2:3), sep = "..")
names(out) <- colnames(m)
m <- wrap(as.array(x), list(1, 2:3), sep = "..")
layerNames <- colnames(m)
colnames(m) <- NULL
out[raster::cellFromXY(out, xy)] <- m
raster::values(out)[raster::cellFromXY(out, xy), ] <- m
names(out) <- layerNames
return(out)
}
4 changes: 3 additions & 1 deletion R/ifelse.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
setMethod("ifelse",
signature(test = "magpie"),
function(test, yes, no) {
if (!all(test %in% c(0,1))) stop("'test' must only contain booleans!")
if (!all(suppressWarnings(as.integer(test)) %in% c(0,1))) {
stop("'test' must only contain booleans!")
}
yes <- test*yes
no <- (1 - test)*no
yes[!test] <- 0
Expand Down
22 changes: 12 additions & 10 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FEATURES:
- added coordinates support
- added conversion functions raster <-> magclass
- added collapseDim

NOTES:
* checking dependencies in R code ... NOTE
Missing or unexported object: 'units::install_unit'

This note might occur if an older version of the "units" package is installed on the test system. The magclass package is already prepared for the changes which come with version 0.7.0 of package "units", but it also still works with older versions of the "units" package.
CHANGES:
- removed experimental metadata code (stored in magclass version with tag "metadata" for later reintegration)
- added tests so that the package has now >90% unit test line coverage
- fixed coding style issues
- deprecated function `fulldim` and removed it from all functions in magclass where it had been used.
- dimSums as well as magpply, `add_columns`, `add_dimension` and `getCPR` work now for all (sub-dimension)
- `getItems` can now be used to replace values or even remove dimensions and it supports named vectors (to define element-wise what should be substituted with what)
- `read.magpie` and `write.magpie` have been streamlined (e.g. ncdf support is no longer coupled to 59199 cells) which might lead to slightly different behavior than before in some instances
- added `dim` argument for magclass subsetting (e.g. `x[1, dim = 2]` which is identical to `x[,1,]` - useful for generalization of functions that should act on all main dimensions)
- removed `old_dim_convention` function
- deprecated `getRegionList` (use `getItems` instead)
- replaced `write.report` with `write.report2` and deprecated `write.report2`

0 comments on commit 12a00e5

Please sign in to comment.