Skip to content

Commit

Permalink
Merge pull request #46 from ecohealthalliance/feature/additional_argu…
Browse files Browse the repository at this point in the history
…ments_obfuscate_gps

updated function to allow more control
  • Loading branch information
collinschwantes authored Aug 6, 2024
2 parents 33eccff + e3eccb5 commit 43eb9ce
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("cre", "aut"), comment = c(ORCID = "0000-0003-4014-4896")),
person("Johana", "Teigen", email = "[email protected]", role = "aut", comment = c(ORCID = "0000-0002-6209-2321")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
14 changes: 9 additions & 5 deletions R/obfuscate_gps.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
4 changes: 3 additions & 1 deletion man/get_precision.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion man/obfuscate_gps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 43eb9ce

Please sign in to comment.