exceed_threshold: Check if transformation/coercing of a vector is good enough

Description Usage Arguments Value Examples

View source: R/exceed_threshold.R

Description

This function is primarily aimed to check if the transformation of a vector was successful enough to return the transformed value instead of the original.

Usage

1
2
3
4
5
6
7
8
exceed_threshold(
  original,
  transformed,
  threshold = 0.9,
  force = FALSE,
  ask = FALSE,
  var_name = "the input vector"
)

Arguments

original

the original vector

transformed

the transformed vector with NA-values for non transformed values

threshold

is a numeric value in [0,1] specifying the proportion of cells in transformed that should be recognized as correctly coerced to accept the new class. This does not effect the function output (except when force = TRUE) but will have some diagnostic benefits.

force

Should a candidate vector (candidate according to threshold) be forced to its suggested class (with non-coercible elements set to NA). FALSE by default but if the function is called interactively, the user will also have the option to set force = TRUE on the fly.

ask

this argument gives you the chance to interactively inspect your data and specify if a column is a date or not, on the fly. This is FALSE by default for as.Dates.default but TRUE for as.Dates.dataframe. It only applies when the function is run interactively and only when force == FALSE.

var_name

a name for the object to be used in messages (you could probably just leave this as default, NULL; it is mostly used for internal purposes!).

Value

Either original or transformed.

Examples

1
2
3
4
5
6
7
8
9
x <- c(rep("2012-01-01", 9), "foo")
exceed_threshold(x, as.Date(x))
exceed_threshold(x, as.Date(x), force = TRUE)
exceed_threshold(x, as.Date(x), ask = TRUE)
exceed_threshold(x, as.Date(x), threshold = 1)
exceed_threshold(x, as.Date(x), var_name = "bar", force = TRUE)

x <- c(1:9, "baz")
exceed_threshold(x, suppressWarnings(as.numeric(x)))

incadata documentation built on April 14, 2020, 6:08 p.m.