Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft of anonymizer function #144

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions R/ojo_anonymize.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#' @title Anonymize
#'
#' @description Anonymize one or more columns in a local tibble
#'
#' @param .data A local tibble
#' @param cols A list of columns to anonymize
#' @param ... Placeholder for future arguments
#' @param .keep A character string passed to the `keep` argument of `dplyr::mutate()`. One of "unused" (default), "all", "used", or "none".
#' @param .after <tidy-select> Optionally, control where new columns should appear (the default is to replace the source columns with their anonymized version). See `dplyr::mutate()` for more details.
#'
#' @export
#' @return A local tibble with anonymized columns, with names prefixed with "xx_"
#'
#' @importFrom dplyr everything mutate across
#' @importFrom purrr map_chr
#' @importFrom digest digest
#'
ojo_anonymize <- function(.data, cols = dplyr::everything(), ..., .keep = "unused", .after = NULL) {
if (is.null(.after)) {
.after <- {{cols}}
}

df <- .data |>
dplyr::mutate(
dplyr::across({{cols}}, ~purrr::map_chr(., ~digest::digest(., algo = "xxhash64")), .names = "xx_{.col}"),
.keep = .keep,
.after = .after
)

return(df)
}
Loading