a <- 2
tmpfile1 <- tempfile()
tmpfile2 <- tempfile()
tmpfile3 <- tempfile(fileext = ".grd")
tmpfile4 <- tempfile(fileext = ".grd")
save(a, file = tmpfile1)
save(a, file = tmpfile2)
# treats as character string, so 2 filenames are different
digest::digest(tmpfile1)
digest::digest(tmpfile2)
# tests to see whether character string is representing a file
.robustDigest(tmpfile1)
.robustDigest(tmpfile2) # same
# if you tell it that it is a path, then you can decide if you want it to be
# treated as a character string or as a file path
.robustDigest(asPath(tmpfile1), quick = TRUE)
.robustDigest(asPath(tmpfile2), quick = TRUE) # different because using file info
.robustDigest(asPath(tmpfile1), quick = FALSE)
.robustDigest(asPath(tmpfile2), quick = FALSE) # same because using file content
# SpatRasters are have pointers
if (requireNamespace("terra", quietly = TRUE)) {
r <- terra::rast(system.file("ex/elev.tif", package = "terra"))
r3 <- terra::deepcopy(r)
r1 <- terra::writeRaster(r, filename = tmpfile3)
digest::digest(r)
digest::digest(r3) # different but should be same
.robustDigest(r1)
.robustDigest(r3) # same... data & metadata are the same
# note, this is not true for comparing memory and file-backed rasters
.robustDigest(r)
.robustDigest(r1) # different
}
Run the code above in your browser using DataLab