Skip to content

Commit

Permalink
Adjust some tests and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Jul 5, 2024
1 parent 74fd0c4 commit d5677ce
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 129 deletions.
63 changes: 31 additions & 32 deletions R/gisco_get_airports.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,51 @@
#' \donttest{
#' library(sf)
#'
#' Greece <- gisco_get_countries(country = "EL", resolution = "1")
#' AirP_GC <- gisco_get_airports(country = "EL")
#' AirP_GC <- st_transform(AirP_GC, st_crs(Greece))
#' greece <- gisco_get_countries(country = "EL", resolution = 3)
#' airp_gc <- gisco_get_airports(country = "EL")
#'
#' library(ggplot2)
#'
#'
#' ggplot(Greece) +
#' geom_sf(fill = "grey80") +
#' geom_sf(data = AirP_GC, color = "blue") +
#' labs(
#' title = "Airports on Greece",
#' shape = NULL,
#' color = NULL,
#' caption = gisco_attributions()
#' )
#'
#'
#' if (inherits(airp_gc, "sf")) {
#' ggplot(greece) +
#' geom_sf(fill = "grey80") +
#' geom_sf(data = airp_gc, color = "blue") +
#' labs(
#' title = "Airports on Greece",
#' shape = NULL,
#' color = NULL,
#' caption = gisco_attributions()
#' )
#' }
#' ##############################
#' # Plot ports #
#' ##############################
#'
#' ports <- gisco_get_ports()
#' coast <- giscoR::gisco_coastallines
#'
#' # To Equal Earth projection :)
#' # To Robinson projection :)
#'
#' library(sf)
#' coast <- st_transform(coast, 8857)
#' coast <- st_transform(coast, "ESRI:54030")
#' ports <- st_transform(ports, st_crs(coast))
#'
#'
#' ggplot(coast) +
#' geom_sf(fill = "#F6E1B9", color = "#0978AB") +
#' geom_sf(data = ports, fill = "red", shape = 21) +
#' theme_void() +
#' theme(
#' panel.background = element_rect(fill = "#C6ECFF"),
#' panel.grid = element_blank(),
#' plot.title = element_text(face = "bold", hjust = 0.5),
#' plot.subtitle = element_text(face = "italic", hjust = 0.5)
#' ) +
#' labs(
#' title = "Ports Worldwide", subtitle = "Year 2013",
#' caption = "(c) European Union, 1995 - today"
#' )
#' if (inherits(ports, "sf")) {
#' ggplot(coast) +
#' geom_sf(fill = "#F6E1B9", color = "#0978AB") +
#' geom_sf(data = ports, fill = "red", shape = 21) +
#' theme_void() +
#' theme(
#' panel.background = element_rect(fill = "#C6ECFF"),
#' panel.grid = element_blank(),
#' plot.title = element_text(face = "bold", hjust = 0.5),
#' plot.subtitle = element_text(face = "italic", hjust = 0.5)
#' ) +
#' labs(
#' title = "Ports Worldwide", subtitle = "Year 2013",
#' caption = "(c) European Union, 1995 - today"
#' )
#' }
#' }
#' @export
gisco_get_airports <- function(year = "2013", country = NULL, cache_dir = NULL,
Expand Down
63 changes: 31 additions & 32 deletions man/gisco_get_airports.Rd

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

10 changes: 5 additions & 5 deletions tests/testthat/test-gisco_bulk_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ test_that("Bulk download online", {
cache_dir = tempdir(),
ext = "gdb"
))
expect_silent(gisco_bulk_download(
id_giscoR = "urban_audit",
cache_dir = tempdir(),
year = 2004
))
# expect_silent(gisco_bulk_download(
# id_giscoR = "urban_audit",

Check notice on line 33 in tests/testthat/test-gisco_bulk_download.R

View check run for this annotation

codefactor.io / CodeFactor

tests/testthat/test-gisco_bulk_download.R#L33

Remove commented code. (commented_code_linter)

Check notice

Code scanning / lintr

Commented code should be removed. Note test

Commented code should be removed.
# cache_dir = tempdir(),

Check notice on line 34 in tests/testthat/test-gisco_bulk_download.R

View check run for this annotation

codefactor.io / CodeFactor

tests/testthat/test-gisco_bulk_download.R#L34

Remove commented code. (commented_code_linter)

Check notice

Code scanning / lintr

Commented code should be removed. Note test

Commented code should be removed.
# year = 2004

Check notice on line 35 in tests/testthat/test-gisco_bulk_download.R

View check run for this annotation

codefactor.io / CodeFactor

tests/testthat/test-gisco_bulk_download.R#L35

Remove commented code. (commented_code_linter)

Check notice

Code scanning / lintr

Commented code should be removed. Note test

Commented code should be removed.
# ))
expect_message(gisco_bulk_download(
resolution = 60,
cache_dir = tempdir(),
Expand Down
115 changes: 57 additions & 58 deletions tests/testthat/test-gisco_get_coastallines.R
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
test_that("Coastallines", {
expect_error(gisco_get_coastallines(year = 2001, res = 60))
expect_error(gisco_get_coastallines(year = 2011))
expect_error(gisco_get_coastallines(epsg = 2819))
expect_error(gisco_get_coastallines(spatialtype = "aa"))
expect_error(gisco_get_coastallines(res = 15))
expect_silent(gisco_get_coastallines())
expect_message(gisco_get_coastallines(verbose = TRUE))
expect_true(sf::st_is_longlat(gisco_get_countries()))
})

test_that("Coastal download online", {
skip_on_cran()
skip_if_gisco_offline()

expect_silent(gisco_get_coastallines(resolution = "60"))
expect_silent(gisco_get_coastallines(resolution = "60", cache = FALSE))
expect_silent(gisco_get_coastallines(resolution = 3))
expect_message(gisco_get_coastallines(resolution = "60", verbose = TRUE))
expect_message(gisco_get_coastallines(
resolution = "60",
verbose = TRUE,
update_cache = TRUE
))
cachetest <- paste0(tempdir(), "/coast")
expect_silent(gisco_get_coastallines(
resolution = "60",
cache_dir = cachetest
))

expect_message(a <- gisco_get_coastallines(
resolution = "60", epsg = "3035",
verbose = TRUE
))
b <- gisco_get_coastallines(resolution = "60", epsg = "3857")
c <- gisco_get_coastallines(resolution = "60", epsg = "4326")

epsg3035 <- sf::st_crs(3035)
epsg3857 <- sf::st_crs(3857)
epsg4326 <- sf::st_crs(4326)

expect_identical(epsg3035, sf::st_crs(a))
expect_identical(epsg3857, sf::st_crs(b))
expect_identical(epsg4326, sf::st_crs(c))
})

test_that("Offline", {
options(giscoR_test_offline = TRUE)
expect_message(
n <- gisco_get_coastallines(
resolution = 60, cache_dir = tempdir(),
update_cache = TRUE
),
"not reachable"
)
expect_null(n)
options(giscoR_test_offline = FALSE)
})
test_that("Coastallines", {
expect_error(gisco_get_coastallines(year = 2001, res = 60))
expect_error(gisco_get_coastallines(year = 2011))
expect_error(gisco_get_coastallines(epsg = 2819))
expect_error(gisco_get_coastallines(res = 15))
expect_silent(gisco_get_coastallines())
expect_message(gisco_get_coastallines(verbose = TRUE))
expect_true(sf::st_is_longlat(gisco_get_countries()))
})

test_that("Coastal download online", {
skip_on_cran()
skip_if_gisco_offline()

expect_silent(gisco_get_coastallines(resolution = "60"))
expect_silent(gisco_get_coastallines(resolution = "60", cache = FALSE))
# expect_silent(gisco_get_coastallines(resolution = 3))

Check notice on line 17 in tests/testthat/test-gisco_get_coastallines.R

View check run for this annotation

codefactor.io / CodeFactor

tests/testthat/test-gisco_get_coastallines.R#L17

Remove commented code. (commented_code_linter)

Check notice

Code scanning / lintr

Commented code should be removed. Note test

Commented code should be removed.
expect_message(gisco_get_coastallines(resolution = "60", verbose = TRUE))
expect_message(gisco_get_coastallines(
resolution = "60",
verbose = TRUE,
update_cache = TRUE
))
cachetest <- paste0(tempdir(), "/coast")
expect_silent(gisco_get_coastallines(
resolution = "60",
cache_dir = cachetest
))

expect_message(a <- gisco_get_coastallines(
resolution = "60", epsg = "3035",
verbose = TRUE
))
b <- gisco_get_coastallines(resolution = "60", epsg = "3857")
c <- gisco_get_coastallines(resolution = "60", epsg = "4326")

epsg3035 <- sf::st_crs(3035)
epsg3857 <- sf::st_crs(3857)
epsg4326 <- sf::st_crs(4326)

expect_identical(epsg3035, sf::st_crs(a))
expect_identical(epsg3857, sf::st_crs(b))
expect_identical(epsg4326, sf::st_crs(c))
})

test_that("Offline", {
options(giscoR_test_offline = TRUE)
expect_message(
n <- gisco_get_coastallines(
resolution = 60, cache_dir = tempdir(),
update_cache = TRUE
),
"not reachable"
)
expect_null(n)
options(giscoR_test_offline = FALSE)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-gisco_get_education.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ test_that("Education online", {
# Several countries
nn <- gisco_get_education(country = c("LU", "DK", "BE"))

expect_length(unique(nn$cc), 3)
expect_length(unique(nn$cntr_id), 3)

# Full
eufull <- gisco_get_education()

expect_gt(length(unique(eufull$cc)), 10)
expect_gt(length(unique(eufull$cntr_id)), 10)
})

test_that("Offline", {
Expand Down

0 comments on commit d5677ce

Please sign in to comment.