I see you're using geojsonio to convert sf objects to GeoJSON. Would you consider using geojonsf to improve speed?
Hopefully in this benchmark I'm replicating what you're doing inside topogram
library(microbenchmark)
library(geojsonsf)
library(geojsonio)
microbenchmark(
geojsonsf = {
shape$id <- 1:nrow(shape)
sf_geojson( shape )
},
geojsonio = {
geo_list <- geojson_list(input = shape)
for (i in seq_along(geo_list$features)) {
geo_list$features[[i]]$id <- i - 1
geo_list$features[[i]]$properties$id <- i - 1
}
geo_json <- geojson_json(input = geo_list)
},
times = 5
)
# Unit: milliseconds
# expr min lq mean median uq max neval
# geojsonsf 1.955478 2.078431 2.172361 2.126749 2.226844 2.474302 5
# geojsonio 235.419525 239.354627 241.348199 240.610821 242.299392 249.056631 5
Note, I'm planning an update to geojsonsf by the end of October with some important fixes & updates.
You can also specify package version dependencies inside the DESCRIPTION in place of inside functions
if (packageVersion("geojsonio") < "0.6.0.9100")
stop("You need geojsonio >= 0.6.0.9100 to use this function.", call. = FALSE)
vs
Imports:
htmlwidgets,
geojsonio (>=0.6.09100),
htmltools,
shiny,
rmarkdown,
jsonlite,
magrittr
This way you don't have to implement the version check inside each function which may require it.
I see you're using
geojsonioto convertsfobjects to GeoJSON. Would you consider usinggeojonsfto improve speed?Hopefully in this benchmark I'm replicating what you're doing inside topogram
Note, I'm planning an update to
geojsonsfby the end of October with some important fixes & updates.You can also specify package version dependencies inside the
DESCRIPTIONin place of inside functionsvs
This way you don't have to implement the version check inside each function which may require it.