Skip to content

Commit 421ee6b

Browse files
authored
Fix rcmdcheck warnings (#874)
1 parent 76df847 commit 421ee6b

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

R/layers.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ addRasterLegend <- function(map, x, layer = 1, ...) {
357357
#
358358
# remove the levels to get the raw cell values
359359
levels(x) <- NULL
360-
color_info <- base::subset(color_info, value %in% terra::unique(x)[[1]])
360+
value_in_layer <- color_info$value %in% terra::unique(x)[[1]]
361+
color_info <- color_info[value_in_layer & !is.na(value_in_layer), ]
361362

362363
res <- if (is.data.frame(lvls)) {
363364
# Use the labels from levels(x), and look up the matching colors.

R/normalize-terra.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,24 @@ polygonData.SpatVector <- function(obj) {
5151

5252
# helpers -----------------------------------------------------------------
5353
assure_crs_terra <- function(x) {
54-
prj <- crs(x, proj=TRUE)
55-
if (is.lonlat(x, perhaps=TRUE, warn=FALSE)) {
54+
stopifnot(is_installed("terra"))
55+
56+
prj <- raster::crs(x, proj = TRUE)
57+
58+
if (is.na(prj) || (prj == "")) {
59+
# Don't have enough information to check
60+
warning("SpatVector layer is not long-lat data", call. = FALSE)
61+
return(x)
62+
}
63+
64+
if (terra::is.lonlat(x, perhaps = TRUE, warn = FALSE)) {
5665
if (!grepl("+datum=WGS84", prj, fixed = TRUE)) {
57-
x <- project(x, "+proj=longlat +datum=WGS84")
66+
x <- terra::project(x, "+proj=longlat +datum=WGS84")
5867
}
59-
return(x)
60-
}
61-
# Don't have enough information to check
62-
if (is.na(crs) || (crs=="")) {
63-
warning("SpatVector layer is not long-lat data", call. = FALSE)
6468
return(x)
6569
}
66-
project(x, "+proj=longlat +datum=WGS84")
70+
71+
terra::project(x, "+proj=longlat +datum=WGS84")
6772
}
6873

6974
check_crs_terra <- function(x) {

0 commit comments

Comments
 (0)