#' @title \emph{changeCoords}: function used to change coordinate names.
#' @description An internal function used to change the coordinate names for datasets.
#' @param data A list of datasets.
#' @param oldcoords The old coordinate names.
#' @param newcoords The new coordinate names.
#' @return A list of data.frame or spatial objects with the coordinate names changed.
changeCoords <- function(data, oldcoords, newcoords) {
lapply(data, function(dat) {
if (inherits(dat,'data.frame')) {
if (inherits(dat, 'sf')) dat
else
if (!all(oldcoords %in% names(dat))) stop('Coordinate names specified not in dataset.')
else {
names(dat)[names(dat) == oldcoords] <- newcoords
dat
}
}
else {
if (!all(oldcoords %in% colnames(dat@coords))) stop('Coordinate names specified not in dataset.')
else {
colnames(dat@coords) <- newcoords
dat
}
}
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.