phil@google.com
2004-Jun-13 06:54 UTC
[Rd] can't create a POSIXct from an actual Unix timestamp (PR#6975)
Full_Name: Philip Gross Version: 1.9.0 OS: Linux Redhat 9.0 Submission from: (NULL) (65.57.245.11) Among the many conversions for POSIXct values, there does not seem to be one which will accept an actual POSIX timestamp, e.g. as produced by MySQL's UNIX_TIMESTAMP() function. I have fixed this by adding the following lines to R-1.9.0/src/library/base/R/datetime.R , at line 89: if(is.numeric(x)) return(structure(x, class = c("POSIXt", "POSIXct"))) I am far from an R guru, and this was done based on pattern matching the code. It seems to work, though.
Prof Brian Ripley
2004-Jun-13 08:45 UTC
(PR#6975) [Rd] can't create a POSIXct from an actual Unix timestamp
On Sun, 13 Jun 2004 phil@google.com wrote:> Full_Name: Philip Gross > Version: 1.9.0 > OS: Linux Redhat 9.0 > Submission from: (NULL) (65.57.245.11) > > > Among the many conversions for POSIXct values, there does not seem to be one > which will accept an actual POSIX timestamp, e.g. as produced by MySQL's > UNIX_TIMESTAMP() function. I have fixed this by adding the following lines to > R-1.9.0/src/library/base/R/datetime.R , at line 89: > > if(is.numeric(x)) > return(structure(x, class = c("POSIXt", "POSIXct"))) > > I am far from an R guru, and this was done based on pattern matching the code. > It seems to work, though.This cannot be correct, as the numeric value could be the integer number of days after 1980-01-01, for example. This is a deliberate omission, but you will note (I hope) that R does handle actual Unix timestamps in e.g. Sys.time() and file.info(). (They use code equivalent to yours, *when* the interpretation of the number is known, *and* x is known to be double and not integer.) Note this is not a bug, and would not have been even if your suggestion had been correct. Please read the section on BUGS in the FAQ. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Reasonably Related Threads
- find_by_sql timestamp parameter
- How to get back POSIXct format after calculating with hist() results
- how to get a histogram of an POSIXct vector ?
- axis.POSIXct: Datetime data and plotting
- segfault during build of 2.1.0 on RH9; print.POSIXct implicated (PR#7827)