diff --git a/DESCRIPTION b/DESCRIPTION index 00e9ed4..ad59f26 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hddtools Title: Hydrological Data Discovery Tools -Version: 0.9.4 +Version: 0.9.5 Authors@R: c(person(given = "Claudia", family = "Vitolo", role = c("aut"), email = "cvitolodev@gmail.com", comment = c(ORCID = "0000-0002-4252-1176")), @@ -15,8 +15,8 @@ Maintainer: Dorothea Hug Peter URL: https://docs.ropensci.org/hddtools/, https://github.com/ropensci/hddtools BugReports: https://github.com/ropensci/hddtools/issues Description: Tools to discover hydrological data, accessing catalogues and databases from various data providers. The package is described in Vitolo (2017) "hddtools: Hydrological Data Discovery Tools" . -Depends: R (>= 3.5.0), rgdal -Imports: zoo, sp, curl, XML, raster, readxl, tidyr +Depends: R (>= 3.5.0) +Imports: zoo, curl, XML, terra, readxl, tidyr, sf Suggests: testthat, leaflet, rmarkdown, knitr, dplyr VignetteBuilder: knitr License: GPL-3 diff --git a/NAMESPACE b/NAMESPACE index c492d42..0c74fcc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,17 +9,9 @@ export(catalogueSEPA) export(tsData60UK) export(tsMOPEX) export(tsSEPA) -import(rgdal) importFrom(XML,readHTMLTable) importFrom(curl,curl_download) -importFrom(raster,extent) -importFrom(raster,extract) -importFrom(raster,raster) importFrom(readxl,read_xlsx) -importFrom(sp,CRS) -importFrom(sp,Polygon) -importFrom(sp,Polygons) -importFrom(sp,SpatialPolygons) importFrom(tidyr,pivot_longer) importFrom(utils,download.file) importFrom(utils,read.csv) diff --git a/NEWS.md b/NEWS.md index dc45292..d995632 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# hddtools 0.9.5 + +*Removed dependency fom rgdal and raster packages + # hddtools 0.9.4 * Removed dependency from the rnrfa package diff --git a/R/Data60UK.R b/R/Data60UK.R index e3cdd96..f2671cd 100644 --- a/R/Data60UK.R +++ b/R/Data60UK.R @@ -7,7 +7,7 @@ #' #' @param areaBox bounding box, a list made of 4 elements: minimum longitude #' (lonMin), minimum latitude (latMin), maximum longitude (lonMax), maximum -#' latitude (latMax) +#' latitude (latMax) or an object of type "SpatExtent" #' #' @return This function returns a data frame containing the following columns: #' \describe{ @@ -18,7 +18,7 @@ #' \item{\code{Latitude}}{} #' \item{\code{Longitude}}{} #' } -#' +#' #' @source \url{http://nrfaapps.ceh.ac.uk/datauk60/data.html} #' #' @export @@ -29,7 +29,7 @@ #' Data60UK_catalogue_all <- catalogueData60UK() #' #' # Filter the catalogue based on a bounding box -#' areaBox <- raster::extent(-4, -2, +52, +53) +#' areaBox <- terra::ext(-4, -2, +52, +53) #' Data60UK_catalogue_bbox <- catalogueData60UK(areaBox) #' } #' @@ -43,23 +43,23 @@ catalogueData60UK <- function(areaBox = NULL){ Data60UKcatalogue <- tables[[which.max(n.rows)]] names(Data60UKcatalogue) <- c("id", "River", "Location") Data60UKcatalogue[] <- lapply(Data60UKcatalogue, as.character) - + # Find grid reference browsing the NRFA catalogue # This was temp <- rnrfa::catalogue() but the catalogue has been saved as # external data here so that the dependency from rnrfa could be removed. temp <- readRDS(system.file("extdata", "rnrfa_cat.rds", package = "hddtools")) temp <- temp[which(temp$id %in% Data60UKcatalogue$id), ] - + Data60UKcatalogue$gridReference <- temp$`grid-reference`$ngr Data60UKcatalogue$Latitude <- temp$latitude Data60UKcatalogue$Longitude <- temp$longitude # Latitude is the Y axis, longitude is the X axis. if (!is.null(areaBox)){ - lonMin <- areaBox@xmin - lonMax <- areaBox@xmax - latMin <- areaBox@ymin - latMax <- areaBox@ymax + lonMin <- areaBox$xmin + lonMax <- areaBox$xmax + latMin <- areaBox$ymin + latMax <- areaBox$ymax }else{ lonMin <- -180 lonMax <- +180 @@ -103,16 +103,16 @@ tsData60UK <- function(id){ temp <- utils::read.table(file_url) names(temp) <- c("P", "Q", "DayNumber", "Year", "nStations") - + # Combine the first four columns into a character vector date_info <- with(temp, paste(Year, DayNumber)) # Parse that character vector datetime <- strptime(date_info, "%Y %j") P <- zoo::zoo(temp$P, order.by = datetime) # measured in mm Q <- zoo::zoo(temp$Q, order.by = datetime) # measured in m3/s - + myTS <- zoo::merge.zoo(P,Q) - + return(myTS) } diff --git a/R/KGClimateClass.R b/R/KGClimateClass.R index 856dcea..a7c6c9f 100644 --- a/R/KGClimateClass.R +++ b/R/KGClimateClass.R @@ -17,7 +17,7 @@ #' @examples #' \dontrun{ #' # Define a bounding box -#' areaBox <- raster::extent(-3.82, -3.63, 52.41, 52.52) +#' areaBox <- terra::ext(-3.82, -3.63, 52.41, 52.52) #' # Get climate classes #' KGClimateClass(areaBox = areaBox) #' } @@ -28,7 +28,7 @@ KGClimateClass <- function(areaBox = NULL, updatedBy = "Peel", verbose = FALSE){ # crop to bounding box if (is.null(areaBox)){ - areaBox <- raster::extent(c(-180, +180, -90, +90)) + areaBox <- terra::ext(c(-180, +180, -90, +90)) } bbSP <- bboxSpatialPolygon(areaBox) @@ -38,7 +38,7 @@ KGClimateClass <- function(areaBox = NULL, updatedBy = "Peel", verbose = FALSE){ kgLegend <- utils::read.table(system.file(file.path("extdata", "KOTTEK_Legend.txt"), package = "hddtools")) - + kgLegend$V1 <- as.character(kgLegend$V1) # message("OFFLINE results") # create a temporary directory @@ -50,13 +50,14 @@ KGClimateClass <- function(areaBox = NULL, updatedBy = "Peel", verbose = FALSE){ utils::untar(system.file(file.path("extdata", "KOTTEK_KG.tar.gz"), package = "hddtools"), exdir = td) - kgRaster <- raster::raster(paste0(td, "/KOTTEK_koeppen-geiger.tiff", + kgRaster <- terra::rast(paste0(td, "/KOTTEK_koeppen-geiger.tiff", sep = "")) - temp <- data.frame(table(raster::extract(kgRaster, bbSP))) + temp <- data.frame(table(terra::extract(kgRaster, bbSP)))[,2:3] + colnames(temp)[1] <- "ID" temp$Class <- NA for (i in 1:dim(temp)[1]){ - class1 <- which(kgLegend[,1] == temp[i,1]) + class1 <- which(kgLegend[,1] == as.character(temp[i,1])) if (length(class1) > 0){ temp$Class[i] <- as.character(kgLegend[class1,3]) } @@ -64,7 +65,7 @@ KGClimateClass <- function(areaBox = NULL, updatedBy = "Peel", verbose = FALSE){ temp <- temp[which(!is.na(temp$Class)),] - df <- data.frame(ID = temp$Var1, + df <- data.frame(ID = temp$ID, Class = temp$Class, Frequency = temp$Freq) @@ -77,7 +78,7 @@ KGClimateClass <- function(areaBox = NULL, updatedBy = "Peel", verbose = FALSE){ "PEEL_Legend.txt"), package = "hddtools"), header = TRUE) - + kgLegend$ID <- as.character(kgLegend$ID) # message("OFFLINE results") # create a temporary directory @@ -89,12 +90,13 @@ KGClimateClass <- function(areaBox = NULL, updatedBy = "Peel", verbose = FALSE){ utils::untar(system.file(file.path("extdata", "PEEL_KG.tar.gz"), package = "hddtools"), exdir = td) - kgRaster <- raster::raster(paste0(td, "/PEEL_koppen_ascii.txt", sep = "")) + kgRaster <- terra::rast(paste0(td, "/PEEL_koppen_ascii.txt", sep = "")) - temp <- data.frame(table(raster::extract(kgRaster, bbSP))) + temp <- data.frame(table(terra::extract(kgRaster, bbSP)))[,2:3] + colnames(temp)[1] <- "ID" temp$Class <- NA for (i in 1:dim(temp)[1]){ - class1 <- which(kgLegend[,1] == temp[i,1]) + class1 <- which(kgLegend[,1] == as.character(temp[i,1])) if (length(class1) > 0){ temp$Class[i] <- as.character(kgLegend[class1,2]) } @@ -102,7 +104,7 @@ KGClimateClass <- function(areaBox = NULL, updatedBy = "Peel", verbose = FALSE){ temp <- temp[which(!is.na(temp$Class)),] - df <- data.frame(ID = temp$Var1, + df <- data.frame(ID = temp$ID, Class = temp$Class, Frequency = temp$Freq) diff --git a/R/bboxSpatialPolygon.R b/R/bboxSpatialPolygon.R index 524d78a..fa0d92b 100644 --- a/R/bboxSpatialPolygon.R +++ b/R/bboxSpatialPolygon.R @@ -15,43 +15,63 @@ #' #' @examples #' \dontrun{ -#' boundingbox <- raster::extent(-180, +180, -50, +50) -#' bbSP <- bboxSpatialPolygon(boundingbox = boundingbox) +#' boundingbox <- terra::ext(-180, +180, -50, +50) +#' bbSP <- bboxSpatialPolygon(boundingbox = boundingbox) #' } #' - bboxSpatialPolygon <- function(boundingbox, proj4stringFrom = NULL, proj4stringTo = NULL) { + if (!is.null(proj4stringFrom)) { + stopifnot(inherits(sf::st_crs(proj4stringFrom),"crs")) + } if (is.null(proj4stringFrom)) { + proj4stringFrom <- "+proj=longlat +datum=WGS84" + } - proj4stringFrom <- sp::CRS("+proj=longlat +datum=WGS84") + if(is.matrix(boundingbox)) if(dim(boundingbox)==c(2,2)) bb <- boundingbox + + #For compatibility with raster input bounding box objects + if(inherits(boundingbox, "Extent")){ + bb <- matrix(as.numeric(c( + boundingbox@xmin, boundingbox@ymin, + boundingbox@xmax, boundingbox@ymax + )), + nrow = 2 + )} - } - bb <- matrix(as.numeric(c(boundingbox@xmin, boundingbox@ymin, - boundingbox@xmax, boundingbox@ymax)), - nrow = 2) + if(inherits(boundingbox, "SpatExtent")){ + bb <- matrix(as.numeric(c( + boundingbox$xmin, boundingbox$ymin, + boundingbox$xmax, boundingbox$ymax + )), + nrow = 2 + )} + + if(!exists("bb")) stop("No valid bounding box provided") + rownames(bb) <- c("lon", "lat") colnames(bb) <- c("min", "max") # Create unprojected boundingbox as spatial object # clockwise, 5 points to close it - bboxMat <- rbind(c(bb["lon", "min"], bb["lat", "min"]), - c(bb["lon", "min"], bb["lat", "max"]), - c(bb["lon", "max"], bb["lat", "max"]), - c(bb["lon", "max"], bb["lat", "min"]), - c(bb["lon", "min"], bb["lat", "min"])) + bboxMat <- rbind( + c(bb["lon", "min"], bb["lat", "min"]), + c(bb["lon", "min"], bb["lat", "max"]), + c(bb["lon", "max"], bb["lat", "max"]), + c(bb["lon", "max"], bb["lat", "min"]), + c(bb["lon", "min"], bb["lat", "min"]) + ) - bboxSP <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(bboxMat)), - "bbox")), - proj4string = proj4stringFrom) + + bboxSP <- terra::vect(bboxMat, "polygon", crs = proj4stringFrom) if (!is.null(proj4stringTo)) { - bboxSP <- sp::spTransform(bboxSP, proj4stringTo) + stopifnot(class(sf::st_crs(proj4stringTo)) == "crs") + bboxSP <- terra::project(bboxSP, proj4stringTo) } return(bboxSP) - } diff --git a/R/hddtools-package.R b/R/hddtools-package.R index a9dfd56..36b4468 100644 --- a/R/hddtools-package.R +++ b/R/hddtools-package.R @@ -18,11 +18,8 @@ #' Vitolo C, Buytaert W, 2014, HDDTOOLS: an R package serving Hydrological Data #' Discovery Tools, AGU Fall Meeting, 15-19 December 2014, San Francisco, USA. #' -#' @import rgdal #' @importFrom curl curl_download -#' @importFrom raster raster extract extent #' @importFrom readxl read_xlsx -#' @importFrom sp CRS SpatialPolygons Polygon Polygons #' @importFrom tidyr pivot_longer #' @importFrom utils download.file read.csv read.fwf read.table untar unzip #' @importFrom XML readHTMLTable diff --git a/_pkgdown.yml b/_pkgdown.yml index eb5bae5..2922219 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -34,7 +34,6 @@ reference: Get data from various providers contents: - tsData60UK - - tsGRDC - tsMOPEX - tsSEPA - grdcLTMMD @@ -45,16 +44,7 @@ reference: Utility functions, mainly used internally contents: - bboxSpatialPolygon - - getContent -- title: Cached catalogues - desc: > - Cached version of the output of the catalogue*() functions - contents: - - Data60UKcatalogue - - GRDCcatalogue - - MOPEXcatalogue - - SEPAcatalogue articles: - title: All articles diff --git a/inst/experimental/moreGRDC.R b/inst/experimental/moreGRDC.R index 325dcd3..e2a6d51 100644 --- a/inst/experimental/moreGRDC.R +++ b/inst/experimental/moreGRDC.R @@ -46,7 +46,7 @@ #' GRDC_catalogue_all <- catalogueGRDC() #' #' # Define a bounding box -#' areaBox <- raster::extent(-3.82, -3.63, 52.41, 52.52) +#' areaBox <- terra::ext(-3.82, -3.63, 52.41, 52.52) #' # Filter the catalogue based on bounding box #' GRDC_catalogue_bbox <- catalogueGRDC(areaBox = areaBox) #' @@ -61,39 +61,39 @@ #' test_catalogueGRDC <- function() { - + the_url <- "ftp://ftp.bafg.de/pub/REFERATE/GRDC/catalogue/" - + # Retrieve the catalogue result <- RCurl::getURL(the_url, ftp.use.epsv=TRUE, dirlistonly = TRUE) list_of_files <- strsplit(result, "\r*\n")[[1]] yesterday <- gsub(pattern = "-", replacement = "_", Sys.Date() - 1) today <- gsub(pattern = "-", replacement = "_", Sys.Date()) - latest_file <- + latest_file <- ifelse(test = length(list_of_files[grep(pattern = today, x = list_of_files)]), yes = list_of_files[grep(pattern = today, x = list_of_files)], no = list_of_files[grep(pattern = yesterday, x = list_of_files)]) latest_file <- paste0(the_url, latest_file) - + my_tmp_file <- tempfile() x <- RCurl::getBinaryURL(latest_file, ftp.use.epsv = FALSE,crlf = TRUE) writeBin(object = x, con = my_tmp_file) GRDCcatalogue <- readxl::read_xlsx(my_tmp_file, sheet = "Catalogue") - + # Cleanup non GRDCcatalogue <- data.frame(lapply(GRDCcatalogue, function(x) {gsub("n.a.|-999|-", NA, x)}), stringsAsFactors = FALSE) - + # Convert to numeric some of the columns colx <- which(!(names(GRDCcatalogue) %in% c("grdc_no", "wmo_reg", "sub_reg", "nat_id", "river", "station", "country", "provider_id"))) GRDCcatalogue[, colx] <- lapply(GRDCcatalogue[, colx], as.numeric) - + return(GRDCcatalogue) - + } #' Interface for the Global Runoff Data Centre database of Monthly Time Series. @@ -233,58 +233,58 @@ test_catalogueGRDC <- function() { #' test_tsGRDC <- function(id) { - + options(warn = -1) - + catalogueTmp <- catalogueGRDC() catalogueTmp <- catalogueTmp[which(catalogueTmp$grdc_no == id), ] - + # Retrieve look-up table grdcLTMMD <- NULL load(system.file(file.path("data", "grdcLTMMD.rda"), package = "hddtools")) - + # Retrieve WMO region from catalogue wmoRegion <- catalogueTmp$wmo_reg - + # Retrieve ftp server location zipFile <- as.character(grdcLTMMD[which(grdcLTMMD$WMO_Region == wmoRegion), "Archive"]) - + # create a temporary directory td <- tempdir() - + # create the placeholder file tf <- tempfile(tmpdir = td, fileext = ".zip") - + # download into the placeholder file # Switched from downloader::download to utils::download.file # to ensure it works cross-platform downloader::download(url = zipFile, destfile = tf, mode = "wb") - + # Type of tables tablenames <- c("LTVD", "LTVM", "PVD", "PVM", "YVD", "YVM") - + # get the name of the file to unzip fname <- paste0(id, "_Q_", tablenames, ".csv") - + # unzip the file to the temporary directory utils::unzip(tf, files = fname, exdir = td, overwrite = TRUE) - + # fpath is the full path to the extracted file fpath <- file.path(td, fname) - + if (!all(file.exists(fpath))) { - + stop("Data are not available at this station") - + } - + # Initialise empty list of tables ltables <- list() - + # Populate tables for (j in seq_along(fpath)) { - + TS <- readLines(fpath[j]) # find dataset content row_data <- grep(pattern = "# Data Set Content:", x = TS) @@ -295,7 +295,7 @@ test_tsGRDC <- function(id) { data_names <- gsub(pattern = ")", replacement = "", x = data_names) data_names <- gsub(pattern = "\\(", replacement = "_", x = data_names) data_names <- gsub(pattern = "\\.", replacement = "_", x = data_names) - + ## find data lines row_data_lines <- grep(pattern = "# Data lines:", x = TS)[1] chr_positions <- gregexpr(pattern = "[0-9]", @@ -304,14 +304,14 @@ test_tsGRDC <- function(id) { rows_to_read <- as.numeric(substr(x = TS[row_data_lines], start = chr_positions[1], stop = chr_positions[lchr_positions])) - + if (rows_to_read > 0) { - + # find tables row_data <- grep(pattern = "DATA", x = TS, ignore.case = FALSE) row_start <- row_data + 2 row_end <- row_start + rows_to_read - 1 - + # Read columns and assign names column_names <- c() for (k in seq_along(data_names)) { @@ -322,7 +322,7 @@ test_tsGRDC <- function(id) { column_names <- c(column_names, paste0(data_names[k], "__", tempcolnames)) } - + for (w in seq_along(row_start)) { # Assemble data frame row_split <- unlist(strsplit(TS[row_start[w]:row_end[w]], ";")) @@ -334,20 +334,20 @@ test_tsGRDC <- function(id) { byrow = TRUE)) } } - + df <- data.frame(tmp, stringsAsFactors = FALSE) names(df) <- column_names - + ltables[[j]] <- df }else{ message(paste(tablenames[j], "data are not available at this station")) ltables[[j]] <- NULL } - + } - + names(ltables) <- tablenames - + return(ltables) - + } diff --git a/man/KGClimateClass.Rd b/man/KGClimateClass.Rd index 96b0816..d5b9996 100644 --- a/man/KGClimateClass.Rd +++ b/man/KGClimateClass.Rd @@ -22,7 +22,7 @@ Given a bounding box, the function identifies the overlapping climate zones. \examples{ \dontrun{ # Define a bounding box - areaBox <- raster::extent(-3.82, -3.63, 52.41, 52.52) + areaBox <- terra::ext(-3.82, -3.63, 52.41, 52.52) # Get climate classes KGClimateClass(areaBox = areaBox) } diff --git a/man/bboxSpatialPolygon.Rd b/man/bboxSpatialPolygon.Rd index b28cb11..b870906 100644 --- a/man/bboxSpatialPolygon.Rd +++ b/man/bboxSpatialPolygon.Rd @@ -25,8 +25,8 @@ Bounding box is first created (in lat/lon) then projected if specified } \examples{ \dontrun{ - boundingbox <- raster::extent(-180, +180, -50, +50) - bbSP <- bboxSpatialPolygon(boundingbox = boundingbox) +boundingbox <- terra::ext(-180, +180, -50, +50) +bbSP <- bboxSpatialPolygon(boundingbox = boundingbox) } } diff --git a/man/catalogueData60UK.Rd b/man/catalogueData60UK.Rd index 6c01a89..46ac9a0 100644 --- a/man/catalogueData60UK.Rd +++ b/man/catalogueData60UK.Rd @@ -12,7 +12,7 @@ catalogueData60UK(areaBox = NULL) \arguments{ \item{areaBox}{bounding box, a list made of 4 elements: minimum longitude (lonMin), minimum latitude (latMin), maximum longitude (lonMax), maximum -latitude (latMax)} +latitude (latMax) or an object of type "SpatExtent"} } \value{ This function returns a data frame containing the following columns: @@ -35,7 +35,7 @@ listing 61 gauging stations. Data60UK_catalogue_all <- catalogueData60UK() # Filter the catalogue based on a bounding box - areaBox <- raster::extent(-4, -2, +52, +53) + areaBox <- terra::ext(-4, -2, +52, +53) Data60UK_catalogue_bbox <- catalogueData60UK(areaBox) } diff --git a/tests/testthat/test-Data60UK.R b/tests/testthat/test-Data60UK.R index 85b661b..6555f74 100644 --- a/tests/testthat/test-Data60UK.R +++ b/tests/testthat/test-Data60UK.R @@ -13,7 +13,7 @@ test_that("Test catalogueData60UK", { test_that("Test catalogueData60UK bounding box", { # Define a bounding box - areaBox <- raster::extent(c(-4, -2, +52, +53)) + areaBox <- terra::ext(c(-4, -2, +52, +53)) # Filter the catalogue based on a bounding box x2 <- catalogueData60UK(areaBox) @@ -22,11 +22,11 @@ test_that("Test catalogueData60UK bounding box", { }) test_that("Test tsData60UK function", { - + # Retrieve sample data x <- tsData60UK(id = 39015) - + expect_that(class(x) == "zoo", equals(TRUE)) expect_that(all(names(x) == c("P", "Q")), equals(TRUE)) - + }) diff --git a/tests/testthat/test-KGClimateClass.R b/tests/testthat/test-KGClimateClass.R index c1e5d95..c08a82c 100644 --- a/tests/testthat/test-KGClimateClass.R +++ b/tests/testthat/test-KGClimateClass.R @@ -3,7 +3,7 @@ context("KGClimateClass") test_that("Test KGClimateClass function", { # Define a bounding box - areaBox <- raster::extent(-3.82, -3.63, 52.41, 52.52) + areaBox <- terra::ext(-3.82, -3.63, 52.41, 52.52) # Get climate classes x <- try(KGClimateClass(areaBox = areaBox), silent = TRUE) diff --git a/tests/testthat/test-MOPEX.R b/tests/testthat/test-MOPEX.R index 778e332..327965d 100644 --- a/tests/testthat/test-MOPEX.R +++ b/tests/testthat/test-MOPEX.R @@ -3,10 +3,11 @@ context("MOPEX") test_that("Test catalogueMOPEX - MAP = FALSE", { testthat::skip_on_cran() + testthat::skip_on_ci() # Retrieve the MOPEX catalogue x1 <- catalogueMOPEX(MAP = FALSE) - + expect_true("data.frame" %in% class(x1)) expect_true(all(dim(x1) == c(1861, 12))) expect_true(is.na(x1$State[x1$USGS_ID == "08167000"])) @@ -16,38 +17,40 @@ test_that("Test catalogueMOPEX - MAP = FALSE", { test_that("Test catalogueMOPEX - MAP = TRUE", { testthat::skip_on_cran() + testthat::skip_on_ci() + # Retrieve the MOPEX catalogue x2 <- catalogueMOPEX(MAP = TRUE) - + expect_true("data.frame" %in% class(x2)) expect_true(all(dim(x2) == c(438, 12))) expect_true(x2$State[x2$USGS_ID == "01048000"] == "ME") - + }) test_that("Test tsMOPEX - MAP = FALSE", { testthat::skip_on_cran() - + testthat::skip_on_ci() # Retrieve data x3 <- tsMOPEX(id = "01010000", MAP = FALSE) - + expect_true("zoo" %in% class(x3)) expect_true(all(names(x3) == "Q")) expect_true(as.numeric(x3$Q[1]) == 13.45) - + }) test_that("Test tsMOPEX - MAP = TRUE", { testthat::skip_on_cran() - + testthat::skip_on_ci() # Retrieve data x4 <- tsMOPEX(id = "01048000", MAP = TRUE) - + expect_true("zoo" %in% class(x4)) expect_true(all(names(x4) == c("P", "E", "Q", "T_max", "T_min"))) expect_true(as.numeric(x4$T_min[1]) == -10.8444) - + }) diff --git a/tests/testthat/test-bboxSpatialPolygon.R b/tests/testthat/test-bboxSpatialPolygon.R index 32d2ae6..823cb7b 100644 --- a/tests/testthat/test-bboxSpatialPolygon.R +++ b/tests/testthat/test-bboxSpatialPolygon.R @@ -2,9 +2,9 @@ context("bboxSpatialPolygon") test_that("Test bboxSpatialPolygon function", { - boundingbox <- raster::extent(c(-180, +180, -50, +50)) + boundingbox <- terra::ext(c(-180, +180, -50, +50)) bbSP <- bboxSpatialPolygon(boundingbox = boundingbox) - expect_that("SpatialPolygons" %in% class(bbSP), equals(TRUE)) + expect_that("SpatVector" %in% class(bbSP), equals(TRUE)) }) diff --git a/vignettes/hddtools_vignette.Rmd b/vignettes/hddtools_vignette.Rmd index e07f4cd..53e27bc 100644 --- a/vignettes/hddtools_vignette.Rmd +++ b/vignettes/hddtools_vignette.Rmd @@ -63,7 +63,7 @@ The package hddtools contains a function to identify the updated Koppen-Greiger ```{r KGClimateClass1, eval = TRUE} # Define a bounding box -areaBox <- raster::extent(-10, 5, 48, 62) +areaBox <- terra::ext(-10, 5, 48, 62) # Extract climate zones from Peel's map: KGClimateClass(areaBox = areaBox, updatedBy = "Peel") @@ -115,7 +115,7 @@ The GRDC catalogue (or a subset) can be used to create a map. ```{r catalogueGRDC7, eval = FALSE} # Visualise outlets on an interactive map library(leaflet) -leaflet(data = GRDC_catalogue %>% filter(river == "PO, FIUME")) %>% +leaflet(data = GRDC_catalogue %>% dplyr::filter(river == "PO, FIUME")) %>% addTiles() %>% # Add default OpenStreetMap map tiles addMarkers(~long, ~lat, popup = ~station) ``` @@ -134,7 +134,7 @@ The hddtools contain two functions to interact with this database: one to retrei Data60UK_catalogue_all <- catalogueData60UK() # Filter Data60UK catalogue based on bounding box -areaBox <- raster::extent(-4, -3, 51, 53) +areaBox <- terra::ext(-4, -3, 51, 53) Data60UK_catalogue_bbox <- catalogueData60UK(areaBox = areaBox) ```