diff --git a/.travis.yml b/.travis.yml index 9e68419..f492e78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,6 @@ language: R sudo: false cache: packages -r_github_packages: - - tidyverse/ggplot2 - addons: apt: sources: diff --git a/DESCRIPTION b/DESCRIPTION index ab028b9..1e57630 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,9 +12,9 @@ Description: Spatial data plus the power of the ggplot2 framework means easier m License: GPL-3 Depends: R (>= 2.10), - ggplot2 (>= 2.0), - sf + ggplot2 (>= 2.2.1.9000) Imports: + sf, rosm (>= 0.2), abind, reshape2, diff --git a/tests/testthat/test-annotation-scale.R b/tests/testthat/test-annotation-scale.R index 6d114a8..f63006f 100644 --- a/tests/testthat/test-annotation-scale.R +++ b/tests/testthat/test-annotation-scale.R @@ -2,7 +2,7 @@ context("test-annotation-scale.R") test_that("scale bar parameters are generated correctly", { load_longlake_data() - nc <- read_sf(system.file("shape/nc.shp", package="sf")) + nc <- sf::read_sf(system.file("shape/nc.shp", package="sf")) expect_equal( scalebar_params( @@ -42,7 +42,7 @@ test_that("scale bar parameters are generated correctly", { test_that("annotation scale works as intended", { load_longlake_data() - nc <- read_sf(system.file("shape/nc.shp", package="sf")) + nc <- sf::read_sf(system.file("shape/nc.shp", package="sf")) # defaults are ok print( diff --git a/tests/testthat/test-df_spatial.R b/tests/testthat/test-df_spatial.R index 4b3f2cc..039c58b 100644 --- a/tests/testthat/test-df_spatial.R +++ b/tests/testthat/test-df_spatial.R @@ -28,76 +28,78 @@ test_that("Spatial* objects are fortified correctly", { # load the long lake test data load_longlake_data() - # SpatialPoints - spoints_df <- as(longlake_depthdf, "Spatial") - spoints <- sp::SpatialPoints(spoints_df, proj4string = spoints_df@proj4string) - expect_df_spatial(spoints) - expect_equal(nrow(df_spatial(spoints)), length(spoints)) - expect_df_spatial(spoints_df, c("NOTES", "DEPTH.M")) - - # SpatialMultiPoints - spmultipoints_sf <- dplyr::summarise(dplyr::group_by(longlake_depthdf, NOTES), one = 1) - spmultipoints_df <- as(spmultipoints_sf, "Spatial") - spmultipoints <- as(spmultipoints_df, "SpatialMultiPoints") - - expect_df_spatial(spmultipoints) - expect_df_spatial(spmultipoints_df, c("NOTES", "one")) - expect_true(setequal(df_spatial(spmultipoints_df)$NOTES, c("mouth of inlet", "reeds", NA))) - - # SpatialLines - splines_df <- as(sf::st_zm(longlake_roadsdf), "Spatial") - splines <- sp::SpatialLines(splines_df@lines, proj4string = splines_df@proj4string) - line <- splines@lines[[1]]@Lines[[1]] - lines <- splines@lines[[1]] - - expect_df_spatial(line) - - expect_df_spatial(lines, c("coordinate_id", "piece_id")) - expect_is(df_spatial(lines)$coordinate_id, "integer") - expect_is(df_spatial(lines)$piece_id, "factor") - - expect_df_spatial(splines, c("coordinate_id", "piece_id")) - expect_is(df_spatial(splines)$coordinate_id, "integer") - expect_is(df_spatial(splines)$piece_id, "factor") - - expect_df_spatial(splines_df, c("coordinate_id", "piece_id", "FEAT_CODE")) - expect_is(df_spatial(splines_df)$coordinate_id, "integer") - expect_is(df_spatial(splines_df)$piece_id, "factor") - - # manual check of success - # ggplot(df_spatial(splines)) + geom_path(aes(x, y, group = piece_id)) - # ggplot(df_spatial(splines_df)) + geom_path(aes(x, y, group = piece_id)) - - # SpatialPolygons - spoly_df <- as(sf::st_zm(longlake_waterdf), "Spatial") - spoly <- as(spoly_df, "SpatialPolygons") - polygon <- spoly@polygons[[1]]@Polygons[[1]] - polygons <- spoly@polygons[[1]] - - expect_df_spatial(polygon, c("is_hole", "ring_direction")) - - expect_df_spatial(polygons, c("coordinate_id", "piece_id")) - expect_is(df_spatial(polygons)$coordinate_id, "integer") - expect_is(df_spatial(polygons)$piece_id, "factor") - - expect_df_spatial(spoly, c("coordinate_id", "piece_id")) - expect_is(df_spatial(spoly)$coordinate_id, "integer") - expect_is(df_spatial(spoly)$piece_id, "factor") - - expect_df_spatial(spoly_df, c("coordinate_id", "piece_id")) - expect_is(df_spatial(spoly_df)$coordinate_id, "integer") - expect_is(df_spatial(spoly_df)$piece_id, "factor") - - # manual check of success - # ggplot(df_spatial(spoly)) + geom_polypath(aes(x, y, group = piece_id)) - # ggplot(df_spatial(spoly_df)) + geom_polypath(aes(x, y, group = piece_id)) - - # sf points, multipoints, lines, polygons, and sfc - expect_identical(df_spatial(longlake_depthdf), df_spatial(spoints_df)) - expect_identical(df_spatial(spmultipoints_sf), df_spatial(spmultipoints_df)) - expect_identical(df_spatial(longlake_roadsdf), df_spatial(splines_df)) - expect_identical(df_spatial(longlake_waterdf), df_spatial(spoly_df)) - expect_df_spatial(longlake_depthdf$geometry) + withr::with_package("sf", { + # SpatialPoints + spoints_df <- as(longlake_depthdf, "Spatial") + spoints <- sp::SpatialPoints(spoints_df, proj4string = spoints_df@proj4string) + expect_df_spatial(spoints) + expect_equal(nrow(df_spatial(spoints)), length(spoints)) + expect_df_spatial(spoints_df, c("NOTES", "DEPTH.M")) + + # SpatialMultiPoints + spmultipoints_sf <- dplyr::summarise(dplyr::group_by(longlake_depthdf, NOTES), one = 1) + spmultipoints_df <- as(spmultipoints_sf, "Spatial") + spmultipoints <- as(spmultipoints_df, "SpatialMultiPoints") + + expect_df_spatial(spmultipoints) + expect_df_spatial(spmultipoints_df, c("NOTES", "one")) + expect_true(setequal(df_spatial(spmultipoints_df)$NOTES, c("mouth of inlet", "reeds", NA))) + + # SpatialLines + splines_df <- as(sf::st_zm(longlake_roadsdf), "Spatial") + splines <- sp::SpatialLines(splines_df@lines, proj4string = splines_df@proj4string) + line <- splines@lines[[1]]@Lines[[1]] + lines <- splines@lines[[1]] + + expect_df_spatial(line) + + expect_df_spatial(lines, c("coordinate_id", "piece_id")) + expect_is(df_spatial(lines)$coordinate_id, "integer") + expect_is(df_spatial(lines)$piece_id, "factor") + + expect_df_spatial(splines, c("coordinate_id", "piece_id")) + expect_is(df_spatial(splines)$coordinate_id, "integer") + expect_is(df_spatial(splines)$piece_id, "factor") + + expect_df_spatial(splines_df, c("coordinate_id", "piece_id", "FEAT_CODE")) + expect_is(df_spatial(splines_df)$coordinate_id, "integer") + expect_is(df_spatial(splines_df)$piece_id, "factor") + + # manual check of success + # ggplot(df_spatial(splines)) + geom_path(aes(x, y, group = piece_id)) + # ggplot(df_spatial(splines_df)) + geom_path(aes(x, y, group = piece_id)) + + # SpatialPolygons + spoly_df <- as(sf::st_zm(longlake_waterdf), "Spatial") + spoly <- as(spoly_df, "SpatialPolygons") + polygon <- spoly@polygons[[1]]@Polygons[[1]] + polygons <- spoly@polygons[[1]] + + expect_df_spatial(polygon, c("is_hole", "ring_direction")) + + expect_df_spatial(polygons, c("coordinate_id", "piece_id")) + expect_is(df_spatial(polygons)$coordinate_id, "integer") + expect_is(df_spatial(polygons)$piece_id, "factor") + + expect_df_spatial(spoly, c("coordinate_id", "piece_id")) + expect_is(df_spatial(spoly)$coordinate_id, "integer") + expect_is(df_spatial(spoly)$piece_id, "factor") + + expect_df_spatial(spoly_df, c("coordinate_id", "piece_id")) + expect_is(df_spatial(spoly_df)$coordinate_id, "integer") + expect_is(df_spatial(spoly_df)$piece_id, "factor") + + # manual check of success + # ggplot(df_spatial(spoly)) + geom_polypath(aes(x, y, group = piece_id)) + # ggplot(df_spatial(spoly_df)) + geom_polypath(aes(x, y, group = piece_id)) + + # sf points, multipoints, lines, polygons, and sfc + expect_identical(df_spatial(longlake_depthdf), df_spatial(spoints_df)) + expect_identical(df_spatial(spmultipoints_sf), df_spatial(spmultipoints_df)) + expect_identical(df_spatial(longlake_roadsdf), df_spatial(splines_df)) + expect_identical(df_spatial(longlake_waterdf), df_spatial(spoly_df)) + expect_df_spatial(longlake_depthdf$geometry) + }) }) test_that("Raster* objects are converted properly by df_spatial", {