I'm pretty new to R and I am trying to create a function with some geographical output. I am trying to include some if/else statements to set defaults for certain parameters like the map title but have been encountering the same issue repeatedly. Others have had the same issue but the responses their queries haven't helped me.
Below is a simplified version of my code, as well as the errors I am encountering.
my_function <- function(x, y, map.title, a, ... ){
neighbours <- spdep::poly2nb(x, queen=T, snap=T)
print("neighbours defined")
local <- spdep::localmoran(y, listw=nb2listw(neighbours, style="W"))
moran_map <- x
moran_map@data <- cbind(x@data, local)
if(map.title = NULL) {
seg_map <- tmap::tm_shape(moran_map) +
tm_fill(col = "Ii",
style = "quantile",
title = "Local Moran's I Statistic") +
tm_layout(title = "Good Maps Have Titles")
return(map)
} else {
seg_map <- tmap::tm_shape(moran_map) +
tm_fill(col = 'Ii',
style = 'quantile',
title = "Local Moran's I Statistic",
palette = a) +
tm_layout(title = map.title)
return(map)
}
}
I keep getting the following errors.
>Error: no function to return from, jumping to top level
> }
Error: unexpected '}' in " }"
> }
Error: unexpected '}' in " }"
Does anyone know what I am doing wrong, and how I could fix this?
Thanks so much!
Aucun commentaire:
Enregistrer un commentaire