| Title: | Simple Data Frame Validation and Quality Checks |
|---|---|
| Description: | Checks a data frame for common data quality issues, including missing values, outliers, duplicate rows, and type inconsistencies. Results are returned as a structured 'validation_report' object with 'print' and 'plot' methods for quick inspection. |
| Authors: | Ugyen Norbu [aut, cre] |
| Maintainer: | Ugyen Norbu <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-10-12 10:11:03 UTC |
| Source: | https://github.com/ugyennorbu/validater |
Examines specified character columns of a data frame and tests
whether their non-missing values can be parsed as dates under a
given format. If at least 80% (but less than 100%) of a column's
non-missing values parse successfully, the column is flagged, and
the row positions of the non-parsable ("straggler") values are
reported for inspection. Unlike check_numeric_like(), this check does not
attempt to guess a date format automatically - the caller must supply
the expected format for each column to be checked, since date formats
are ambiguous (for example, "03/04/2023" could mean March 4th or
April 3rd depending on convention) and guessing incorrectly could
silently produce misleading results.
check_date_like(data, date_columns)check_date_like(data, date_columns)
data |
A data frame. |
date_columns |
A named character vector, where each name is a
column in |
A named list, one element per flagged column (named by column name). Each element is itself a list containing:
Always "date".
Percentage of non-missing values that were successfully parsed under the given format, rounded to 2 decimals.
Integer vector of row indices whose values could not be parsed under the given format.
Returns an empty list if no columns are flagged.
df <- data.frame( signup_date = c( "2023-01-15", "2023-02-20", "not a date", "2023-03-10", "2023-04-01" ), notes = c("a", "b", "c", "d", "e") ) check_date_like(df, date_columns = c(signup_date = "%Y-%m-%d"))df <- data.frame( signup_date = c( "2023-01-15", "2023-02-20", "not a date", "2023-03-10", "2023-04-01" ), notes = c("a", "b", "c", "d", "e") ) check_date_like(df, date_columns = c(signup_date = "%Y-%m-%d"))
Identifies exact duplicate rows across all columns of a data frame.
check_duplicates(data)check_duplicates(data)
data |
A data frame |
A list where each element is an integer vector giving the row indices of a group of duplicate rows. Returns an empty list if no duplicates are found.
df <- data.frame( x = c(1, 2, 1, 4, 5, 4, 4), y = c("a", "b", "a", "d", "e", "d", "d") ) check_duplicates(df)df <- data.frame( x = c(1, 2, 1, 4, 5, 4, 4), y = c("a", "b", "a", "d", "e", "d", "d") ) check_duplicates(df)
Computes the count and percentage of missing (NA) values for each
column in a data frame.
check_missing(data)check_missing(data)
data |
A data frame. |
A data frame with one row per column of data, containing:
Name of the column.
Number of missing values.
Percentage of missing values, rounded to 2 decimals.
df <- data.frame(x = c(1, NA, 3), y = c("a", "b", NA)) check_missing(df)df <- data.frame(x = c(1, NA, 3), y = c("a", "b", NA)) check_missing(df)
Examines each character column of a data frame and tests whether its non-missing values can be converted to numeric. If at least 80% (but less than 100%) of non-missing values are numeric-looking, the column is flagged as likely intended to be numeric, and the row positions of the non-convertible ("straggler") values are reported for inspection. Columns that are already numeric, or that fall below the 80% threshold, are not flagged.
check_numeric_like(data)check_numeric_like(data)
data |
A data frame. |
A named list, one element per flagged column (named by column name). Each element is itself a list containing:
The type the column is likely meant to be
(currently always "numeric").
Percentage of non-missing values that can be converted to numeric, rounded to 2 decimals.
Integer vector of row indices whose values could not be converted to numeric.
Returns an empty list if no columns are flagged.
df <- data.frame( income = c("50000", "62000", "N/A", "48000", "71000"), city = c("Thimphu", "Paro", "Punakha", "Wangdue", "Trongsa"), stringsAsFactors = FALSE ) check_numeric_like(df)df <- data.frame( income = c("50000", "62000", "N/A", "48000", "71000"), city = c("Thimphu", "Paro", "Punakha", "Wangdue", "Trongsa"), stringsAsFactors = FALSE ) check_numeric_like(df)
Calculates the count and percentage of outlier values using IQR method (values beyond Q1 - 1.5IQR or Q3 + 1.5IQR).
check_outliers(data)check_outliers(data)
data |
A data frame |
A data frame with one row per column of data, containing:
Name of the column.
Number of outlier values.
Percentage of outlier values, rounded to 2 decimals.
df <- data.frame( x = c(1, 2, 3, 4, 100), y = c(10, 12, 11, 13, 12) ) check_outliers(df)df <- data.frame( x = c(1, 2, 3, 4, 100), y = c(10, 12, 11, 13, 12) ) check_outliers(df)
Low-level constructor that assembles already-computed check results
into a single validation_report object. This function does not run
any checks itself — it simply packages results produced elsewhere
(typically by check_missing(), check_outliers(),
check_duplicates(), check_numeric_like(), and check_date_like())
into a structured, classed object. In most cases, users should call
validate_df() instead, which runs all five checks and calls this
constructor automatically.
new_validation_report( df, df_name, missing_result, outliers_result, duplicates_result, numeric_like_result, date_like_result )new_validation_report( df, df_name, missing_result, outliers_result, duplicates_result, numeric_like_result, date_like_result )
df |
The data frame that was checked. Used only to derive dimensions; not stored directly in the report. |
df_name |
A character string giving the name to display for the data frame in printed output. |
missing_result |
Output of |
outliers_result |
Output of |
duplicates_result |
Output of |
numeric_like_result |
Output of |
date_like_result |
Output of |
An object of class validation_report, a list containing:
A list with df_name (character), dim (integer vector
of rows and columns), and timestamp (the time the report was
created).
A list with four elements, missing, outliers,
duplicates, numeric_like and date_like, containing the
corresponding check results.
df <- data.frame(x = c(1, NA, 3), y = c("a", "b", "c")) report <- new_validation_report( df = df, df_name = "df", missing_result = check_missing(df), outliers_result = check_outliers(df), duplicates_result = check_duplicates(df), numeric_like_result = check_numeric_like(df), date_like_result = check_date_like(df, date_columns = c(y = "%Y-%m-%d")) ) class(report)df <- data.frame(x = c(1, NA, 3), y = c("a", "b", "c")) report <- new_validation_report( df = df, df_name = "df", missing_result = check_missing(df), outliers_result = check_outliers(df), duplicates_result = check_duplicates(df), numeric_like_result = check_numeric_like(df), date_like_result = check_date_like(df, date_columns = c(y = "%Y-%m-%d")) ) class(report)
Displays two side-by-side bar charts summarizing a validation_report:
the count of missing values per column, and the count of outliers per
numeric column.
## S3 method for class 'validation_report' plot(x, ...)## S3 method for class 'validation_report' plot(x, ...)
x |
A |
... |
Further arguments passed to or from other methods (currently unused). |
The input x, returned invisibly. Called for its side effect
of producing a plot.
Displays a concise summary of a validation_report, showing the data
frame's dimensions, when it was checked, and how many columns (or
groups, for duplicates) were flagged by each check.
## S3 method for class 'validation_report' print(x, ...)## S3 method for class 'validation_report' print(x, ...)
x |
A |
... |
Further arguments passed to or from other methods (currently unused). |
The input x, returned invisibly.
Runs a full suite of data quality checks on a data frame — missing
values, outliers, duplicate rows, and type inconsistencies — and
returns a single, structured report summarizing the results. This is
the main entry point for the package; most users should start here
rather than calling the individual check_*() functions directly.
validate_df(data, date_columns = NULL)validate_df(data, date_columns = NULL)
data |
A data frame to validate. |
date_columns |
Optional. A named character vector mapping column
names in |
An object of class validation_report. See
new_validation_report() for details on its structure. Printing the
result shows a short summary; the full results for each check are
available under report$results$missing, report$results$outliers,
report$results$duplicates, report$results$numeric_like and
report$results$date_like.
df <- data.frame( age = c(25, 30, NA, 45, 200), income = c("50000", "62000", "N/A", "48000", "71000"), stringsAsFactors = FALSE ) report <- validate_df(df) report # With an optional date check df2 <- data.frame( signup_date = c( "2023-01-15", "2023-02-20", "not a date", "2023-03-10", "2023-04-01" ), stringsAsFactors = FALSE ) report2 <- validate_df(df2, date_columns = c(signup_date = "%Y-%m-%d")) report2df <- data.frame( age = c(25, 30, NA, 45, 200), income = c("50000", "62000", "N/A", "48000", "71000"), stringsAsFactors = FALSE ) report <- validate_df(df) report # With an optional date check df2 <- data.frame( signup_date = c( "2023-01-15", "2023-02-20", "not a date", "2023-03-10", "2023-04-01" ), stringsAsFactors = FALSE ) report2 <- validate_df(df2, date_columns = c(signup_date = "%Y-%m-%d")) report2