# \donttest{
# check if R can run the distance functions
aux <- c(
length(suppressWarnings(packageDescription("raster"))),
length(suppressWarnings(packageDescription("gdistance"))),
length(suppressWarnings(packageDescription("sp"))),
length(suppressWarnings(packageDescription("terra"))))
missing.packages <- sapply(aux, function(x) x == 1)
if (any(missing.packages)) {
message("Sorry, this function requires packages '",
paste(c("raster", "gdistance", "sp", "terra")[missing.packages], collapse = "', '"),
"' to operate. Please install ", ifelse(sum(missing.packages) > 1, "them", "it"),
" before proceeding.")
} else {
# Fetch actel's example shapefile
example.shape <- paste0(system.file(package = "actel")[1], "/example_shapefile.shp")
# import the shape file
x <- shapeToRaster(shape = example.shape, size = 20)
# have a look at the resulting raster,
# where the blank spaces are the land areas
terra::plot(x)
}
rm(aux, missing.packages)
# }
Run the code above in your browser using DataLab