Skip to content

Commit 7c77524

Browse files
committed
#86 ggRGB now with fill delivered, and fixed some test bugs
1 parent 4ef1208 commit 7c77524

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

R/ggRGB.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ ggRGB <- function(img, r = 3, g = 2, b = 1, scale, maxpixels = 500000, stretch =
167167
p <- ggplot() + p + geom_blank(data = df, aes(x = x,y = y))
168168
}
169169
} else {
170-
p <- geom_raster(data = df_raster, aes(x = x, y = y, fill = fill), alpha = alpha)
170+
p <- list(geom_raster(data = df_raster, aes(x = x, y = y, fill = fill), alpha = alpha), scale_fill_identity())
171171
if(!ggLayer) {
172-
p <- ggplot() + p + scale_fill_identity()
172+
p <- ggplot() + p
173173
}
174174
}
175175

tests/testthat/test-ggplot.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ test_that("ggR works with single valued rasters", {
5757
})
5858

5959

60-
test_that("ggRGB returns proper ggplot2 classes or data.frames", {
60+
test_that("ggRGB returns proper ggplot2 classes or data.frames or lists of protos", {
6161

6262
tests <- expand.grid(anno = c(TRUE, FALSE), ggLayer = c(TRUE, FALSE), ggObj = c(TRUE,FALSE), stretch=c("sqrt", "hist", "log", "lin"))
6363
builds <- lapply(seq_len(nrow(tests)), function(i) ggRGB(rlogo, ggObj = tests$ggObj[i], geom_raster = !tests$anno[i], ggLayer = tests$ggLayer[i], stretch = tests$stretch[i] ))
@@ -70,12 +70,12 @@ test_that("ggRGB returns proper ggplot2 classes or data.frames", {
7070
if(!inherits(builds[[which(with(tests, ggObj & ggLayer))[1]]], "ggproto")){
7171
## Current ggplot2 release version
7272
for(s in which(with(tests, ggObj & ggLayer))) expect_is(builds[[s]], "proto", info = tinfo[s])
73-
for(s in which(with(tests, ggObj & ggLayer & anno))) expect_equal(builds[[s]]$geom$objname, "raster_ann", info = tinfo[s])
73+
for(s in which(with(tests, ggObj & ggLayer & anno))) expect_equal(builds[[s]]$geom$objname, "raster_ann", info = tinfo[s])
7474
for(s in which(with(tests, ggObj & ggLayer & !anno))) expect_equal(builds[[s]]$geom$objname, "raster", info = tinfo[s])
7575
} else {
7676
## Upcoming ggplot2 version (>=1.0.1.9002)
77-
for(s in which(with(tests, ggObj & ggLayer & anno))) expect_is(builds[[s]]$geom, "GeomRasterAnn", info = tinfo[s])
78-
for(s in which(with(tests, ggObj & ggLayer & !anno))) expect_is(builds[[s]]$geom, "GeomRaster", info = tinfo[s])
77+
for(s in which(with(tests, ggObj & ggLayer & anno))) expect_is(builds[[s]]$geom, "GeomRasterAnn", info = tinfo[s])
78+
for(s in which(with(tests, ggObj & ggLayer & !anno))) expect_is(builds[[s]], "list", info = tinfo[s])
7979
}
8080

8181
## Data.frames

tests/testthat/test-spectralIndices.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ r <- rast(r)
1919
ml <- rast(ml)
2020
test_that("errors and warnings are emitted", {
2121
expect_error(spectralIndices(r, red = 1, indices = "NDVI"), "you must specify \\*all\\* required bands")
22-
expect_error(spectralIndices(r, red = 1), "you must specify \\*all\\* required bands")
2322
expect_warning(spectralIndices(r, red = 1, nir = 2, indices = c("NDVI", "EVI")), "not specified: blue")
2423
expect_warning(spectralIndices(r, red = 1, nir = 2, blue = 1, index = c("NDVI", "EVI")), "Skipping EVI")
2524
expect_warning(spectralIndices(r, red = 1, nir = 2, blue = 1, index = "EVI", skipRefCheck = TRUE), "raster has no values")
@@ -82,6 +81,8 @@ cdb <- c(
8281
rsOpts(idxdb = cdb)
8382

8483
test_that("custom spectral index",{
84+
expect_is(spectralIndices(lsat, red = 3, indices = "CUSTOM"), "SpatRaster")
85+
expect_is(spectralIndices(lsat, swir1 = 5, indices = "CUSTOM2"), "SpatRaster")
8586
expect_equal(
8687
unique(values(spectralIndices(lsat, red = 3, indices = "CUSTOM"))),
8788
as.matrix(data.frame(CUSTOM=0)))

0 commit comments

Comments
 (0)