# \donttest{
## EXAMPLE 1: Untangle point data.frame and export shapefile
library(sf)
set.seed(1)
# Simulate XY data
pts <- data.frame(X = runif(100), Y = runif(100))
# Anonymise
tangled <- tangles(data = pts, depth = 4, saveTangles = FALSE)
# Restore points
restored_pts <- detangles(
data = tangled[[1]],
tanglerInfo = tangled[[2]],
raster_object = FALSE,
stub = "points",
hash_key = tangled[[2]]$hash,
exportShapefile = TRUE
)
## EXAMPLE 2: Untangle from sf POINT input
sf_pts <- st_as_sf(pts, coords = c("X", "Y"))
# Anonymise sf object
tangled_sf <- tangles(data = sf_pts, depth = 3)
# Restore using sf input
restored_from_sf <- detangles(
data = tangled_sf[[1]],
tanglerInfo = tangled_sf[[2]],
stub = "sf_restore",
hash_key = tangled_sf[[2]]$hash,
exportShapefile = TRUE
)
## EXAMPLE 3: Untangle raster data (terra)
library(terra)
ext_path <- system.file("extdata", package = "tangles")
rast.files <- list.files(path = ext_path, full.names = TRUE)
rasters <- terra::rast(rast.files)
# Anonymise raster
tangled_rast <- tangles(data = rasters, depth = 3, rasterdata = TRUE, raster_object = TRUE)
# Restore raster
restored_rast <- detangles(
data = tangled_rast[[1]],
tanglerInfo = tangled_rast[[2]],
raster_object = TRUE,
stub = "raster_demo",
hash_key = tangled_rast[[2]]$hash,
saveTangles = TRUE
)
# }
Run the code above in your browser using DataLab