phwoar, this is a bit exciting, how about convert all those GADM files to one (Geo)Parquet and open it lazily:
url <- "https://geodata.ucdavis.edu/gadm/gadm4.1/gpkg"
f <- readLines(url)
files <- gsub("\"", "", na.omit(stringr::str_extract(f, "gadm.*\\.gpkg\"")))
gpkgs <- file.path(url, files)
dir.create("raw")
curl::multi_download(gpkgs, file.path("raw", basename(gpkgs)), multiplex = TRUE)
## system("ogrmerge.py -single -o gadm41.parquet raw/*.gpkg -src_layer_field_name country")
library(arrow, warn.conflicts = FALSE)
library(dplyr, warn.conflicts = FALSE)
d <- open_dataset("gadm41.parquet", partitioning = c("country", "GID_0"))
oz <- filter(d, GID_0 == "AUS") |> select(geom, country, NAME_1) |> collect()
plot(wk::wkb(oz$geom[oz$NAME_1 == "Western Australia"]))
I'll do this more carefully and put the file up on source.coop