Learn R Programming

tangles (version 2.0.1)

tangler: Re-apply anonymisation using a stored detangler object

Description

For a given detangler object (from tangles), spatial coordinates or raster data can be re-anonymised using the same transformation sequence. This allows consistent tangling of related datasets using a fixed spatial masking.

Usage

tangler(
  data = NULL,
  tanglerInfo = NULL,
  raster_object = FALSE,
  stub = NULL,
  saveTangles = FALSE,
  exportShapefile = FALSE,
  path = NULL
)

Value

Returns either:

  • A data.frame of spatial coordinates (for point-based data), or

  • A terra::SpatRaster (for raster input)

If saveTangles = TRUE, corresponding outputs are written to .rds, and optionally .tif (for raster) or shapefile (for point).

Arguments

data

A 2-column matrix, data.frame of coordinates, an sf POINT object, or a terra::SpatRaster object.

tanglerInfo

A detangler object returned by tangles, which encodes the anonymisation steps and hash key.

raster_object

Logical; set to TRUE if input is a raster object. This ensures the output is reconstructed as a terra::SpatRaster.

stub

Optional character string for file naming. Combined with the hash key for saved outputs.

saveTangles

Logical; if TRUE, the tangler output is saved as an .rds object, and raster layers as .tif.

exportShapefile

Logical; if TRUE and input is point-based, a shapefile of the tangled data is also exported (no CRS assigned).

path

Directory to write output files if saving is enabled. Defaults tempdir().

Author

Brendan Malone

References

  • CM O’Keefe, S Otorepec, M Elliot, E Mackey, and K O’Hara (2017) The De-Identification Decision Making Framework. CSIRO Reports EP173122 and EP175702. tools:::Rd_expr_doi("10.4225/08/59c169433efd4")

Examples

Run this code
# \donttest{
## Example 1: Tangling a point data.frame
library(digest)
set.seed(123)
pts <- data.frame(X = runif(100), Y = runif(100))

# Anonymise original points
t1 <- tangles(data = pts, depth = 4)

# Tangling a second dataset using the same detangler
tangled_again <- tangler(
  data = pts,
  tanglerInfo = t1[[2]],
  stub = "pt_demo",
  saveTangles = TRUE,
  exportShapefile = TRUE
)

## Example 2: Tangling an sf POINT object
library(sf)
sf_pts <- st_as_sf(pts, coords = c("X", "Y"))

tangled_sf <- tangler(
  data = sf_pts,
  tanglerInfo = t1[[2]],
  stub = "sf_demo",
  saveTangles = TRUE,
  exportShapefile = TRUE
)

## Example 3: Tangling a raster using stored detangler
library(terra)
ext_path <- system.file("extdata", package = "tangles")
rast.files <- list.files(path = ext_path, full.names = TRUE)
rasters <- terra::rast(rast.files)

# Must use a detangler with 90°/180°/270° rotations for raster compatibility
t2 <- tangles(data = rasters, depth = 3, rasterdata = TRUE, raster_object = TRUE)

tangled_rast <- tangler(
  data = rasters,
  tanglerInfo = t2[[2]],
  raster_object = TRUE,
  stub = "r_demo",
  saveTangles = TRUE
)
# }

Run the code above in your browser using DataLab