is_date_string: Does the character vector contain dates?

Description Usage Arguments Value See Also Examples

View source: R/is-date-string.R

Description

Checks that the input contains dates or times.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
assert_all_are_date_strings(
  x,
  format = "%F %T",
  na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop")
)

assert_any_are_date_strings(
  x,
  format = "%F %T",
  na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop")
)

is_date_string(x, format = "%F %T", .xname = get_name_in_parent(x))

Arguments

x

Input to check.

format

Expected format of the dates. See strptime.

na_ignore

A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

.xname

Not intended to be used directly.

Value

A logical vector that is TRUE when the input contains valid dates or times.

See Also

strptime for specifying formats, and the lubridate package for automatic guessing of date formats (and other date manipulation functions).

Examples

1
2
3
x <- c("9999-12-31 23:59:59", "wednesday", NA)
is_date_string(x)
assert_all_are_date_strings("01Aug1979", format = "%d%b%Y") #My DOB!

Example output

There were 2 failures:
  Position     Value      Cause
1        2 wednesday bad format
2        3      <NA>    missing

assertive.datetimes documentation built on July 31, 2020, 1:06 a.m.