diff --git a/DESCRIPTION b/DESCRIPTION index d79b40e..a539de5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,15 +19,17 @@ Imports: dplyr (>= 1.0.6), magrittr (>= 2.0.1), stars (>= 0.5), - rlang (>= 1.0) + rlang (>= 1.0), Depends: R (>= 2.10) Suggests: knitr, rmarkdown, testthat (>= 3.0.0) + withr (>= 2.5.1) Config/testthat/edition: 3 VignetteBuilder: knitr URL: https://github.com/icra/ediblecity, https://icra.github.io/ediblecity/ BugReports: https://github.com/icra/ediblecity/issues +Config/potools/style: explicit diff --git a/R/edible_utils.R b/R/edible_utils.R index be17c5f..3713fa4 100644 --- a/R/edible_utils.R +++ b/R/edible_utils.R @@ -1,4 +1,4 @@ check_sf <- function(x){ #check if x is a sf object - if (all(class(x) != "sf")) rlang::abort("x must be an `sf` object") + if (all(class(x) != "sf")) rlang::abort(tr_("x must be an `sf` object")) } diff --git a/R/indicator_NO2.R b/R/indicator_NO2.R index a4858fb..a5041a4 100644 --- a/R/indicator_NO2.R +++ b/R/indicator_NO2.R @@ -46,7 +46,7 @@ no2_seq <- function(x, } if(!(all(c("land_uses", "no2_seq1", "no2_seq2") %in% colnames(green_df)))) - rlang::abort("green_df must contain the columns 'land_uses', 'no2_seq1' & 'no2_seq2'. See ?no2_seq for details") + rlang::abort(tr_("green_df must contain the columns 'land_uses', 'no2_seq1' & 'no2_seq2'. See ?no2_seq for details")) x_f <- x %>% filter(land_use %in% green_df$land_uses) diff --git a/R/indicator_food.R b/R/indicator_food.R index cc2be73..e23ec9b 100644 --- a/R/indicator_food.R +++ b/R/indicator_food.R @@ -53,7 +53,7 @@ food_production <- function(x, dplyr::select(land_uses, food1, food2) } else { if (!all(c("land_uses", "food1", "food2") %in% colnames(edible_df))) - rlang::abort("edible_df must have the columns 'land_uses', 'food1' and 'food2'. See `?food_production` for details.") + rlang::abort(tr_("edible_df must have the columns 'land_uses', 'food1' and 'food2'. See `?food_production` for details.")) } #filter x based on edible diff --git a/R/indicator_green_capita.R b/R/indicator_green_capita.R index 7a7beb6..2a3b51d 100644 --- a/R/indicator_green_capita.R +++ b/R/indicator_green_capita.R @@ -65,8 +65,8 @@ green_capita <- function( check_sf(x) - if(all(is.null(inh_col), is.null(inhabitants))) rlang::abort("'inhabitants' or 'inh_col' must be provided.") - if(!is.null(inh_col) && is.null(name_col)) rlang::abort("'name_col' must be provided along with 'inh_col'") + if(all(is.null(inh_col), is.null(inhabitants))) rlang::abort(tr_("'inhabitants' or 'inh_col' must be provided.")) + if(!is.null(inh_col) && is.null(name_col)) rlang::abort(tr_("'name_col' must be provided along with 'inh_col'")) if (is.null(green_categories)){ diff --git a/R/indicator_green_distance.R b/R/indicator_green_distance.R index 05bad74..d1ca577 100644 --- a/R/indicator_green_distance.R +++ b/R/indicator_green_distance.R @@ -61,12 +61,12 @@ green_distance <- function(x, green_areas <- green_areas %>% dplyr::filter(area >= min_area) - if(nrow(green_areas) == 0) rlang::warn("No public green areas larger than 'min_area' in 'x'. Returning 'NAs'") + if(nrow(green_areas) == 0) rlang::warn(tr_("No public green areas larger than 'min_area' in 'x'. Returning 'NAs'")) houses <- x %>% dplyr::filter(!!as.symbol(residence_col) %in% residences) - if(nrow(houses) == 0) rlang::abort("No residences found in 'x'") + if(nrow(houses) == 0) rlang::abort(tr_("No residences found in 'x'")) nearest <- sf::st_nearest_feature(houses,green_areas) distance <- sf::st_distance(houses, green_areas[nearest,], by_element = TRUE) diff --git a/R/indicator_heat_island.R b/R/indicator_heat_island.R index 3e477e9..4276832 100644 --- a/R/indicator_heat_island.R +++ b/R/indicator_heat_island.R @@ -49,7 +49,7 @@ UHI <- function( . <- NULL check_sf(x) - if (!("stars" %in% class(SVF))) rlang::abort("SVF must be an object of class 'stars'") + if (!("stars" %in% class(SVF))) rlang::abort(tr_("SVF must be an object of class 'stars'")) city_land_uses <- city_land_uses %>% mutate(pGreen = ifelse(!is.na(pGreen), @@ -71,7 +71,7 @@ UHI <- function( # Reproject SVF if necessary if(sf::st_crs(x_rast) != sf::st_crs(SVF)){ - warning("Reprojecting SVF to ", sf::st_crs(x_rast)[[1]]) + rlang::warn(tr_("Reprojecting SVF to ", sf::st_crs(x_rast)[[1]])) SVF <- sf::st_transform(SVF, sf::st_crs(x_rast)) } diff --git a/R/set_scenario.R b/R/set_scenario.R index 0329acf..7232f96 100644 --- a/R/set_scenario.R +++ b/R/set_scenario.R @@ -69,7 +69,7 @@ set_scenario <- function(x, check_sf(x) #check if land_use col exists - if (!("land_use" %in% colnames(x))) rlang::abort("x needs a column called land_use, see ?set_scenario for more detail") + if (!("land_use" %in% colnames(x))) rlang::abort(tr_("x needs a column called land_use, see ?set_scenario for more detail")) #if area_field is null, calculates de area of each feature if (is.null(area_field)) { diff --git a/R/set_scenario_rationale.R b/R/set_scenario_rationale.R index a141c3c..a3cdbc1 100644 --- a/R/set_scenario_rationale.R +++ b/R/set_scenario_rationale.R @@ -40,7 +40,7 @@ set_scenario_rationale <- function(x, x$land_use[gardens_index] <- city_land_uses$land_uses[city_land_uses$location == "garden"] if (nGardens*pGardens >= length(gardens_index)){ - warning(paste("Only", length(gardens_index), "private gardens out of", nGardens*pGardens, "assumed satisfy the 'min_area_garden'\n")) + rlang::warn(tr_(paste("Only", length(gardens_index), "private gardens out of", nGardens*pGardens, "assumed satisfy the 'min_area_garden'\n"))) } } else if (pGardens < 1){ @@ -72,7 +72,7 @@ set_scenario_rationale <- function(x, if (length(vacant_index) < nVacant*pVacant){ - warning(paste("Only", length(vacant_index), "vacant plots out of", nVacant*pVacant, "assumed satisfy the 'min_area_vacant'\n")) + rlang::warn(tr_(paste("Only", length(vacant_index), "vacant plots out of", nVacant*pVacant, "assumed satisfy the 'min_area_vacant'\n"))) nVacant <- length(vacant_index) } else { @@ -120,7 +120,7 @@ set_scenario_rationale <- function(x, hydroponic_rooftop <- city_land_uses$land_uses[city_land_uses$jobs & city_land_uses$location == 'rooftop'] if (length(rooftop_index) < nRooftop*pRooftop){ - warning(paste("Only", length(rooftop_index), "rooftops out of", nRooftop*pRooftop, "assumed satisfy the 'min_area_rooftop'\n")) + rlang::warn(tr_(paste("Only", length(rooftop_index), "rooftops out of", nRooftop*pRooftop, "assumed satisfy the 'min_area_rooftop'\n"))) nRooftop <- length(rooftop_index) } else { diff --git a/R/utils-potools.R b/R/utils-potools.R new file mode 100644 index 0000000..9169cb9 --- /dev/null +++ b/R/utils-potools.R @@ -0,0 +1,3 @@ +tr_ <- function(...){ + enc2utf8(gettext(paste0(...), domain = "R-pkg")) +} diff --git a/data/SVF.rda b/data/SVF.rda index 3daff78..22b4da7 100644 Binary files a/data/SVF.rda and b/data/SVF.rda differ diff --git a/tests/testthat/test-indicator_heat_island.R b/tests/testthat/test-indicator_heat_island.R index ddadc74..624caaa 100644 --- a/tests/testthat/test-indicator_heat_island.R +++ b/tests/testthat/test-indicator_heat_island.R @@ -1,3 +1,5 @@ +withr::local_envvar(new = c("GTIFF_SRS_SOURCE" = "ESPG")) + test_that("when return_raster an verbose are False, it returns a summary", { UHI(city_example, SVF) %>% expect_s3_class("summaryDefault") diff --git a/vignettes/ediblecity.Rmd b/vignettes/ediblecity.Rmd index 109029a..6646633 100644 --- a/vignettes/ediblecity.Rmd +++ b/vignettes/ediblecity.Rmd @@ -50,11 +50,13 @@ Likewise, all the parameters used by the indicators are defined in `city_land_us The urban heat island indicator can return a summary of values or a `stars` object. It needs a raster representing the Sky view factor. See `?UHI` for more details. We use the `SVF` object provided with the package. ```{r} +withr::local_envvar(new = c("GTIFF_SRS_SOURCE" = "ESPG")) # To avoid CRS warning UHI(scenario, SVF) ``` ```{r} +withr::local_envvar(new = c("GTIFF_SRS_SOURCE" = "ESPG")) # To avoid CRS warning plot(UHI(scenario, SVF, return_raster = TRUE)) ```