Not really. There is no way the origin
date can be changed and remain applicable forever in a session.
If you look at parameters for as.Date
(i.e. function then origin
does not has a default value when x
is in numeric
.
## S3 method for class 'numeric'
as.Date(x, origin, ...)
Perhaps, it would have been a good extension to as.Date
function to provide default
value for origin
.
OP has done write thing to create a wrapper function to remove dependency on origin
. Perhaps the function can be improved slightly like:
Modified function based on suggestions from suggestions from @sm1 and @Gregor.
## if date.origin is not defined then origin will be taken as "1970-01-01
options(date.origin = "1970-01-01")
as.date <- function(x, origin = getOption("date.origin")){
origin <- ifelse(is.null(origin), "1970-01-01", origin)
as.Date(x, origin)
}
## Results: (When date.origin is not set)
## > as.date(0)
## [1] "1970-01-01"
## > as.date(2)
## [1] "1970-01-03"
## Results: (When date.origin is set)
## > options(date.origin = "1970-01-05")
## > as.date(2)
## [1] "1970-01-07"