as.parttime(c("1985-10-18", "1991-08-23", "1996-09-26"))
# [3]>
# [1] "1985-10-18" "1991-08-23" "1996-09-26"
as.parttime(c("1234", "5678"), format = "(?\\d{4})")
# [2]>
# [1] "1234" "5678"
# format function that returns a matrix of components
utf8_str <- function(x) intToUtf8(utf8ToInt(x) - 16)
as.parttime(c("B@", "B@A@"), format = function(x) cbind(year = sapply(x, utf8_str)))
# [2]>
# [1] "2000" "2010"
# format function that returns a parttime object by first pre-processing input
as.parttime("B@BB", format = function(x) as.parttime(utf8_str(x)))
# [1]>
# [1] "2022"
# format function that returns a parttime object by manual construction
as.parttime("AIII", format = function(x) parttime(year = as.numeric(utf8_str(x))))
# [1]>
# [1] "1999"
Run the code above in your browser using DataLab