Learn R Programming

admiraldev (version 1.5.0)

is_valid_dtc: Is this string a valid DTC?

Description

Is this string a valid DTC?

Usage

is_valid_dtc(arg, check_dtc = FALSE)

Value

TRUE if the argument is a valid --DTC string, FALSE otherwise

Arguments

arg

The string to check.

Permitted values

a character scalar, i.e., a character vector of length one

Default value

none

check_dtc

If TRUE, the function will check if the string is a real date or datetime (e.g. "2020-02-31" is not real). Note that NA is a valid datetime.

Permitted values

TRUE, FALSE

Default value

FALSE

Details

If check_dtc is FALSE, the function only checks if the format of the string is valid, i.e. it will not check if the actual date/datetime is real, so calls such as is_valid_dtc("2020-13", check_dtc = FALSE) and is_valid_dtc("2020-12-01T25:00:00", check_dtc = FALSE) will returnTRUE.

See Also

Identifies type of Object with return of TRUE/FALSE: is_auto(), is_order_vars()

Examples

Run this code

## Format is valid, date/datetimes are real
is_valid_dtc("2020-02")
is_valid_dtc("2020-02-28")
is_valid_dtc("2020-02-28T14:43")

# Format is valid, date/datetimes are not real but this is not checked
is_valid_dtc("2020-02-31")
is_valid_dtc("2020-02-28T25:00:00")

# Format is valid, date/datetimes are not real and this is checked
is_valid_dtc("2020-02-31", check_dtc = TRUE)
is_valid_dtc("2020-02-28T25:00:00", check_dtc = TRUE)

Run the code above in your browser using DataLab