# NOT RUN {
# 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("tools"))),
length(suppressWarnings(packageDescription("rgdal"))))
missing.packages <- sapply(aux, function(x) x == 1)
if (any(missing.packages)) {
message("Sorry, this function requires packages '",
paste(c("raster", "gdistance", "sp", "tools", "rgdal")[missing.packages], collapse = "', '"),
"' to operate. Please install ", ifelse(sum(missing.packages) > 1, "them", "it"),
" before proceeding.")
} else {
if (suppressWarnings(require("rgdal"))) {
# Fetch actel's example shapefile location
aux <- system.file(package = "actel")[1]
# import the shape file
x <- loadShape(path = aux, shape = "example_shapefile.shp", size = 20)
# have a look at the resulting raster,
# where the blank spaces are the land areas
raster::plot(x)
} else {
message("Sorry, it appears that rgdal is not being able to load.")
}
}
rm(aux, missing.packages)
# }
Run the code above in your browser using DataLab