gaborcsardi / parsedate

R package to parse dates given in arbitrary formats
65 stars 7 forks source link

parse_date(character(0)) gives error #20

Closed wch closed 5 years ago

wch commented 7 years ago
parse_date(character(0))
#> Error during wrapup: parse_date argument must be character

The problem is due to sapply: if the input is character(0), it returns list(): https://github.com/gaborcsardi/parsedate/blob/a7f4b1e25a8d95778119c48fa39fd489424f2bd0/R/parsedate-package.r#L90

Just another reason to not use sapply. :)

gaborcsardi commented 7 years ago

Yeah. I was young and careless.

gaborcsardi commented 7 years ago

Oh, wait, it wasn't me, actually. :)

wch commented 7 years ago

But I do see that you used sapply elsewhere, so you're not totally innocent.

While you're in there, this line uses partial argument matching for the length.out argument:

https://github.com/gaborcsardi/parsedate/blob/a7f4b1e25a8d95778119c48fa39fd489424f2bd0/R/parsedate-package.r#L88

rep(as.POSIXct(NA), length = length(dates))