check_data: Check Data

Description Usage Arguments Value See Also Examples

Description

Checks whether an object is a data frame. Can also check the number of rows, the names and order and values of the columns as well as whether particular columns form a unique key.

Usage

1
2
3
check_data(x, values = NULL, nrow = NA, exclusive = FALSE,
  order = FALSE, key = character(0), x_name = substitute(x),
  error = TRUE)

Arguments

x

The object to check.

values

NULL (default) or a character vector specifying the column names or a named list specifying the column names and values.

nrow

A flag indicating whether x should have rows (versus no rows) or a missing value indicating no requirements or a count or count range of the number of rows.

exclusive

A flag indicating whether other columns are not permitted.

order

A flag indicating whether the columns have to occur in the same order as values.

key

A character vector of the columns that represent a unique key.

x_name

A string of the name of the object.

error

A flag indicating whether to throw an informative error or immediately generate an informative message if the check fails.

Value

An invisible copy of x (if it doesn't throw an error).

See Also

check_colnames, check_nrow and check_key

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
z <- data.frame(
 Count = c(0L, 3L, 3L, 0L, NA), 
  Longitude = c(0, 0, 90, 90, 180), 
  Latitude = c(0, 90, 90.2, 100, -180),
  Type = factor(c("Good", "Bad", "Bad", "Bad", "Bad"), levels = c("Good", "Bad")),
  Extra = TRUE,
  Comments = c("In Greenwich", "Somewhere else", "I'm lost", 
    "I didn't see any", "Help"), 
  stringsAsFactors = FALSE)

check_data(z, values = list(
  Count = 1,
  Extra = NA,
  Latitude = c(45, 90)
  ), exclusive = TRUE, order = TRUE, nrow = 10L, key = "Longitude", error = FALSE)

Example output

Warning messages:
1: z column names must be identical to 'Count', 'Extra' and 'Latitude' 
2: column Count of z must be class numeric 
3: column Count of z must inherit from classes 'numeric' in that order 
4: column Count of z must not include missing values 
5: column Extra of z must only include missing values 
6: the values in column Latitude of z must lie between 45 and 90 
7: z must have 10 rows 
8: column 'Longitude' in z must be a unique key 

checkr documentation built on May 1, 2019, 6:59 p.m.