rstudio / leaflet

R Interface to Leaflet Maps

Home Page:http://rstudio.github.io/leaflet/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

addPolyline() with SpatVector fails if terra is not loaded because check_crs_terra() is missing depency terra::crs

mkoohafkan opened this issue · comments

When {terra} is not loaded (e.g., individual {terra} functions are imported into package namespace) functions that internally call check_crs_terra() will fail. I think this is because check_crs_terra() simply calls crs() instead of terra::crs():

check_crs_terra <- function(x) {
crs <- crs(x)
# Don't have enough information to check
if (is.na(crs) || (crs==""))
return()
if (identical(terra::is.lonlat(x), FALSE)) {
warning("SpatVector layer is not long-lat data", call. = FALSE)
}
prj <- crs(x, proj=TRUE)
if (!grepl("+datum=WGS84", prj, fixed = TRUE)) {
warning(
"SpatVector layer has inconsistent datum (", prj, ").\n",
"Need '+proj=longlat +datum=WGS84'",
call. = FALSE
)
}
}

I encounter this issue when calling addPolylines() with SpatVector objects.

Possible fix:

  • Add {rlang} as Import package
  • Call rlang::check_installed("terra") within check_crs_terra()

Or use wch's staticimports for checking if package is installed.

I think it's a little of all of the above, but mostly the fix is to call terra::crs() rather than crs().