I am trying to convert a raster to geodatabase (gdb) file using R and then read this gdb file back into R. The gdb file contains a column (gridcode) that I need for other calculations within my R script. In ArcGIS this conversion can be done with the 'raster to Polygon' tool but so far I can't find a way to do the same in R. Does anyone know of an R package that can do this?
library(terra)
library(stars)
library(sf)
f <- system.file("extdata/asia.tif", package = "tidyterra")
x <- rast(f)
gdb <- as.gdb(x) ##dummy
mygdb <- st_read('gdb', layer = "first Layer")
st_layers()
plot(st_geometry(mygdb))