mercredi 1 avril 2015

Checking if date is blank in R?

An easy one but I am sure someone knows how to do this...


In R, I was looking for something like is.blank to error trap in my function where a User can specify a date or it can be blank and we will default to use Today's date (i.e. Sys.Date())


I tried



end.date <- ""

# then in function
if (date.end == "" || is.null(date.end)) {
message("end date not specified and so setting to today")
date.end = Sys.Date()
}


But this freaks out charToDate(), i.e.



test.end == ""
Error in charToDate(x) :
character string is not in a standard unambiguous format


Please advise how does one check for blank dates in base R? (And any other wisdom for error trapping dates...)


Aucun commentaire:

Enregistrer un commentaire