if( requireNamespace('raster') ) {
# open example file as RasterLayer
r_path = system.file('external/rlogo.grd', package='raster')
r = raster::raster(r_path, band=1)
g = sk(r)
# convert back to RasterLayer and compare
r_from_g = sk_export(g, 'raster')
print(r)
print(r_from_g)
# NOTE: layer name, band number, and various other metadata are lost
all.equal(r_from_g, r)
}
# same with terra
if( requireNamespace('terra') ) {
# convert all layers
r = terra::rast(r_path)
g = sk(r)
r_from_g = sk_export(g)
# NOTE: various metadata are lost
all.equal(r_from_g, r)
}
Run the code above in your browser using DataLab