Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI progress #779

Merged
merged 5 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ Imports:
rlang,
utils
Suggests:
rmapshaper,
cartogram,
rmapshaper,
cartogram,
rmarkdown,
knitr,
png,
Expand All @@ -53,7 +53,7 @@ Suggests:
dplyr,
tidyr,
shiny,
testthat,
testthat (>= 3.0.0),
terra,
colorspace,
covr,
Expand All @@ -66,3 +66,4 @@ VignetteBuilder: knitr
RoxygenNote: 7.2.3
Config/Needs/check: Nowosad/spDataLarge, lwgeom
Config/Needs/coverage: Nowosad/spDataLarge, lwgeom
Config/testthat/edition: 3
5 changes: 4 additions & 1 deletion examples/tm_layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ tm_shape(World, projection="+proj=robin") +
tm_credits("Robinson projection", position = c("right", "BOTTOM")) +
tm_style("natural", earth.boundary = c(-180, -87, 180, 87), inner.margins = .05) +
tm_legend(position=c("left", "bottom"), bg.color="grey95", frame=TRUE)

# Not working yet
\dontrun{
# Example to illustrate the type of titles
tm_shape(World) +
tm_polygons(c("income_grp", "economy"), title = c("Legend Title 1", "Legend Title 2")) +
Expand All @@ -77,6 +78,8 @@ tm_shape(World) +
panel.label.color = "purple",
legend.text.color = "brown")

}

\dontrun{
# global option tmap.style demo

Expand Down
5 changes: 4 additions & 1 deletion man/tm_layout.Rd

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

80 changes: 0 additions & 80 deletions tests/testing_terra_stars.R

This file was deleted.

12 changes: 12 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(tmap)

test_check("tmap")
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/terra-stars.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# terra works

Code
tm_shape(land_terra) + tm_raster("treess")
Error <simpleError>
Visual values used for the variable, "col" of layer function "tm_raster" are incorrect.

77 changes: 77 additions & 0 deletions tests/testthat/test-terra-stars.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

test_that("terra works", {

skip_on_cran()
landsat = terra::rast(system.file("raster/landsat.tif", package = "spDataLarge"))
# Probably a bug in terra?
# names become cover_cover, cover_cls_cover_cls
land_terra = terra::rast(tmap::land)
names(land_terra) <- names(tmap::land)
tm_shape(land_terra) + tm_raster("trees")

expect_snapshot(error = TRUE, {
tm_shape(land_terra) + tm_raster("treess")
})

# FIXME this is not expected.

tm_shape(landsat) +
tm_rgb(tm_mv("landsat_4", "landsat_3", "landsat_2"), col.scale = tm_scale_rgb(maxValue = 31961))
# Defaults of stars and terra are identical.
tm_shape(landsat) + tm_raster(col.free = FALSE)
tm_shape(landsat) +
tm_raster(c("landsat_1", "landsat_2", "landsat_3", "landsat_4"), col.free = FALSE) +
tm_options(max.raster = 10000)

skip_on_os("linux")
tm_shape(landsat) + tm_raster("landsat_1", col.free = FALSE)

})

test_that("stars works", {

skip_on_cran()
landsat = stars::read_stars(system.file("raster/landsat.tif", package = "spDataLarge"))
land_stars = tmap::land

tm_shape(land_stars) + tm_raster("trees")
tm_shape(land_stars) + tm_raster("treess")

expect_warning(tm_shape(landsat) + tm_raster("landsat.tif", col.free = FALSE))

p <- tm_shape(landsat) + tm_raster(col.free = FALSE)
tm_shape(landsat) +
tm_raster("landsat.tif") +
tm_facets("band") + tm_options(max.raster = 10000)
})





test_that("multi rast works.", {
multi_raster_file = system.file("raster/landsat.tif", package = "spDataLarge")
multi_rast = terra::rast(multi_raster_file)
expect_no_error({
tm_shape(multi_rast[[3:1]]) +
tm_rgb()
})

tm_shape(multi_rast) +
tm_rgb(tm_mv("landsat_4", "landsat_3", "landsat_2"), col.scale = tm_scale_rgb(maxValue = 31961))

})

test_that("Both approaches work for stars.", {
skip_on_cran()
# idea: tm_attr to specify an attribute as mv
# direct approach
landsat_stars = stars::read_stars(system.file("raster/landsat.tif", package = "spDataLarge"))
tm_shape(landsat_stars) +
tm_rgb(tm_mv_dim("band", c(4,3,2)), col.scale = tm_scale_rgb(maxValue = 31961))

# indirect approach
landsat_stars2 = split(landsat_stars, "band")
tm_shape(landsat_stars2) +
tm_rgb(tm_mv("X4", "X3", "X2"), col.scale = tm_scale_rgb(maxValue = 31961))
})
81 changes: 81 additions & 0 deletions tests/testthat/test-tm_layers_aux.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
skip_on_cran()
test_that("Aux layers work.", {

data(World,metro,land)

World$pop_class = cut(World$pop_est, breaks = c(0, 10, 100, 1000, Inf) * 1e6, labels = c("Small", "Medium", "Large", "Extra Large"))
World$HPI_class = cut(World$HPI, breaks = seq(10, 50, by = 10))
World$well_being_class = cut(World$well_being, breaks = seq(2, 8, by = 2))
World$footprint_class = cut(World$footprint, breaks = seq(0, 16, by = 4))

metro$pop2020_class = cut(metro$pop2020, breaks = c(.5, 1.5, 2.5, 5, 15, 40) * 1e6)
Africa = World[World$continent == "Africa", ]
})

test_that("Base layer works at different positions", {
Africa = World[World$continent == "Africa", ]

tm_basemap("OpenStreetMap")+
tm_shape(Africa) +
tm_polygons("HPI", fill.scale = tm_scale(values = "viridis")) +
tm_symbols(size = "pop_est", fill = "purple", size.scale = tm_scale(values = tmap_seq(0, 2, "sqrt"))) +
tm_facets_wrap("well_being_class") +
tm_shape(metro) +
tm_symbols(fill = "pop2020") +
tm_layout(bg.color = "grey95")

tm_shape(Africa) +
tm_polygons("HPI", fill.scale = tm_scale(values = "viridis")) +
tm_basemap("OpenStreetMap")+
tm_symbols(size = "pop_est", fill = "purple", size.scale = tm_scale(values = tmap_seq(0, 2, "sqrt"))) +
tm_facets_wrap("well_being_class") +
tm_shape(metro) +
tm_symbols(fill = "pop2020") +
tm_layout(bg.color = "grey95")

tm_shape(Africa) +
tm_polygons("HPI", fill.scale = tm_scale(values = "viridis")) +
tm_symbols(size = "pop_est", fill = "purple", size.scale = tm_scale(values = tmap_seq(0, 2, "sqrt"))) +
tm_facets_wrap("well_being_class") +
tm_shape(metro) +
tm_basemap("OpenStreetMap")+
tm_symbols(fill = "pop2020") +
tm_layout(bg.color = "grey95")

tm_shape(Africa) +
tm_polygons("HPI", fill.scale = tm_scale(values = "viridis")) +
tm_symbols(size = "pop_est", fill = "purple", size.scale = tm_scale(values = tmap_seq(0, 2, "sqrt"))) +
tm_facets_wrap("well_being_class") +
tm_shape(metro) +
tm_symbols(fill = "pop2020") +
tm_basemap("OpenStreetMap")+
tm_layout(bg.color = "grey95")

tm_shape(Africa) + tm_basemap("OpenStreetMap") +
tm_polygons("pop_est_dens") +
tm_facets_grid("footprint_class", "HPI_class")

tm_shape(Africa) +
tm_basemap("Esri.NatGeoWorldMap") +
tm_borders(lwd = 2) +
tm_shape(metro) +
tm_symbols(fill = "pop2020_class", col = "black")
})

test_that("Projected CRS warp work", {
tm_shape(NLD_prov) +
tm_basemap("OpenStreetMap") +
tm_borders()
})


test_that("Reproject shape to long-lat works.", {
tm_shape(NLD_prov, crs = 4326) +
tm_basemap("OpenStreetMap") +
tm_borders(lwd = 4)


tm_shape(NLD_muni, crs = 4326) +
tm_basemap("OpenStreetMap") +
tm_polygons(c("pop_0_14", "pop_15_24", "pop_25_44", "pop_45_64", "pop_65plus"), fill.free = FALSE, fill_alpha = 0.5)
})
6 changes: 6 additions & 0 deletions tests/testthat/test-tm_layers_polygons.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("tm_borders work", {
# Borders only
map <- tm_shape(World) + tm_borders()
map
expect_equal(map[[1]]$shp_name, "World")
})
3 changes: 3 additions & 0 deletions tests/testthat/test-tmap_mode.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("tmap_mode is plot by default.", {
expect_message(tmap_mode(), "current tmap mode is \"plot\"")
})
Loading
Loading