From e3eccb58ce5e3c51e862fc9b6ff646ddd6831d46 Mon Sep 17 00:00:00 2001 From: Collin Schwantes Date: Tue, 6 Aug 2024 14:50:43 -0600 Subject: [PATCH] updated function to allow more control --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/obfuscate_gps.R | 14 +++++++++----- man/get_precision.Rd | 4 +++- man/obfuscate_gps.Rd | 13 ++++++++++++- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0b75626..708637e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: ohcleandat Type: Package Title: One Health Data Cleaning and Quality Checking Package -Version: 0.3.2 +Version: 0.3.3 Authors@R: c( person("Collin", "Schwantes", email = "schwantes@ecohealthalliance.org", role = c("cre", "aut"), comment = c(ORCID = "0000-0003-4014-4896")), person("Johana", "Teigen", email = "teigen@ecohealthalliance.org", role = "aut", comment = c(ORCID = "0000-0002-6209-2321")), diff --git a/NEWS.md b/NEWS.md index 1d91398..9b65d50 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# ohcleandat 0.3.3 + +* Adds more control over the function used in `get_precision` and `obfuscate_gps` + # ohcleandat 0.3.2 * Fixing issue with `download_google_drive` where search pattern is over applied. diff --git a/R/obfuscate_gps.R b/R/obfuscate_gps.R index f1f5bbe..16a30a8 100644 --- a/R/obfuscate_gps.R +++ b/R/obfuscate_gps.R @@ -11,6 +11,8 @@ #' to the gps measurements. This is used to generate the random uniform #' distribution `runif(1,min = -fuzz, max = fuzz)` #' @param type Character. One of "lat" or "lon" +#' @param func Function. Function used in `get_precision` +#' @param ... Additional arguments for func. #' #' @return Numeric. A vector of fuzzed and rounded GPS points #' @export @@ -57,11 +59,12 @@ #' obfuscate_gps(fuzz = 1, type = "lat") #' } #' -obfuscate_gps <- function(x, precision = 2, fuzz = 0.125, type = c("lat","lon")){ +obfuscate_gps <- function(x, precision = 2, fuzz = 0.125, type = c("lat","lon"), + func = min, ...){ ## max precision in your data # find value in x with most decimal points - data_precision <- get_precision(x,func = min) + data_precision <- get_precision(x,func = func,...) msg_data_precision <- sprintf("The data have a max precision of: %s",data_precision) message(msg_data_precision) @@ -183,6 +186,7 @@ obfuscate_lon <- function(x, precision = 2, fuzz = 0.125){ #' @param x Numeric. Vector of gps points #' @param func Function. Apply some function to the vector of precisions. Default is c so that #' all values are returned +#' @param ... Additional arguments to pass to func. #' #' @return output of func - likely a vector #' @export @@ -194,9 +198,9 @@ obfuscate_lon <- function(x, precision = 2, fuzz = 0.125){ #' get_precision(x,func = min) #' #' -get_precision <- function(x,func = c) { - # number of characters with the decimal - number of chacters without it +get_precision <- function(x,func = c,...) { + # number of characters with the decimal - number of characters without it precision <- 10^-(nchar(gsub("\\.", "", as.character(x))) - nchar(as.character(trunc(x)))) - out <- func(precision) + out <- func(precision,...) return(out) } diff --git a/man/get_precision.Rd b/man/get_precision.Rd index 51e356c..f83f2b5 100644 --- a/man/get_precision.Rd +++ b/man/get_precision.Rd @@ -4,13 +4,15 @@ \alias{get_precision} \title{Get Precision} \usage{ -get_precision(x, func = c) +get_precision(x, func = c, ...) } \arguments{ \item{x}{Numeric. Vector of gps points} \item{func}{Function. Apply some function to the vector of precisions. Default is c so that all values are returned} + +\item{...}{Additional arguments to pass to func.} } \value{ output of func - likely a vector diff --git a/man/obfuscate_gps.Rd b/man/obfuscate_gps.Rd index c69e348..bbc4162 100644 --- a/man/obfuscate_gps.Rd +++ b/man/obfuscate_gps.Rd @@ -6,7 +6,14 @@ \alias{obfuscate_lon} \title{Obfuscate GPS} \usage{ -obfuscate_gps(x, precision = 2, fuzz = 0.125, type = c("lat", "lon")) +obfuscate_gps( + x, + precision = 2, + fuzz = 0.125, + type = c("lat", "lon"), + func = min, + ... +) obfuscate_lat(x, precision = 2, fuzz = 0.125) @@ -23,6 +30,10 @@ to the gps measurements. This is used to generate the random uniform distribution \code{runif(1,min = -fuzz, max = fuzz)}} \item{type}{Character. One of "lat" or "lon"} + +\item{func}{Function. Function used in \code{get_precision}} + +\item{...}{Additional arguments for func.} } \value{ Numeric. A vector of fuzzed and rounded GPS points