library(terra)
r <- rast(matrix(1:90, ncol = 3), crs = "EPSG:3857")
r
# Create tibble
as_tbl <- as_tibble(r, xy = TRUE)
as_tbl
# From tibble
newrast <- as_spatraster(as_tbl, crs = "EPSG:3857")
newrast
Run the code above in your browser using DataLab