Skip to contents

problems() is a companion helper function to create_iso8601(). It retrieves ISO 8601 parsing problems from an object of class iso8601, which is create_iso8601()'s return value and that might contain a problems attribute in case of parsing failures. problems() is a helper function that provides easy access to these parsing problems.

Usage

problems(x = .Last.value)

Arguments

x

An object of class iso8601, as typically obtained from a call to create_iso8601(). The argument can also be left empty, in that case problems() will use the last returned value, making it convenient to use immediately after create_iso8601().

Value

If there are no parsing problems in x, then the returned value is NULL; otherwise, a tibble of parsing failures is returned. Each row corresponds to a parsing problem. There will be a first column named ..i indicating the position(s) in the inputs to the create_iso8601() call that resulted in failures; remaining columns correspond to the original input values passed on to create_iso8601(), with columns being automatically named ..var1, ..var2, and so on, if the inputs to create_iso8601() were unnamed, otherwise, the original variable names are used instead.

Examples

dates <-
  c(
    "2020-01-01",
    "2020-02-11",
    "2020-01-06",
    "2020-0921",
    "2020/10/30",
    "2020-12-05",
    "20231225"
  )

# By inspecting the problematic dates it can be understood that
# the `.format` parameter needs to updated to include other variations.
iso8601_dttm <- create_iso8601(dates, .format = "y-m-d")
problems(iso8601_dttm)
#> # A tibble: 3 × 2
#>     ..i ..var1    
#>   <int> <chr>     
#> 1     4 2020-0921 
#> 2     5 2020/10/30
#> 3     7 20231225  

# Including more parsing formats addresses the previous problems
formats <- c("y-m-d", "y-md", "y/m/d", "ymd")
iso8601_dttm2 <- create_iso8601(dates, .format = list(formats))

# So now `problems()` returns `NULL` because there are no more parsing issues.
problems(iso8601_dttm2)

# If you pass named arguments when calling `create_iso8601()` then they will
# be used to create the problems object.
iso8601_dttm3 <- create_iso8601(date = dates, .format = "y-m-d")
problems(iso8601_dttm3)
#> # A tibble: 3 × 2
#>     ..i date      
#>   <int> <chr>     
#> 1     4 2020-0921 
#> 2     5 2020/10/30
#> 3     7 20231225