I have a function like so:
foo = function(time_in){
# code here that changes POSIXct to numeric
time_out = as.POSIXct(time_in, origin = '1970-01-01')
}
where the user enters time_in
as a POSIXct object. I use this parameter in a linear model (lm()
) which spits my value back out as a numeric. Finally, I want to convert it back to a POSIXct object for my user. The problem is, as.POSIXct()
requires an origin
which is typically Jan 1, 1970 UTC. But what if my user is working off a different origin? How can I extract the origin from time_in
to use it as an argument for time_out
?
I have looked for documentation on how to get the origin, but str(time_in)
and attributes(time_in)
don't give me anything and I haven't found much else. Since this will be in a package, I'd like to stick with base R functions to limit the number of dependencies needed.
as.POSIXct
object, it's origin is1970-01-01
as far as I am aware. It doesn't store an origin. From?as.POSIXct
- "...the origin of time for the ‘"POSIXct"’ class, ‘1970-01-01 00:00.00 UTC’... – MizzenmastDate
andPOSIXct
class, identifying the origin should be as simple asx - as.numeric (x)
. ForPOSIXct
, this should be moot, since the origin is always 1970-01-01 – Armijoas.POSIXct
with a number, so I thought origin must be stored. No, it's just being pedantic and you must specify 1970 for it to do what you expect. – Acceptance