Dear Jeff,

2014-05-21 9:33 GMT+02:00 Jeff Newmiller <jdnew...@dcn.davis.ca.us>:

> You did not show us how "x" was created, so we cannot tell whether this
> indicates a bug or not. My bet would be that "x' was created in some way
> that bypassed the standard POSIXct creation code.
>

I debugged it, this morning:

The problem stems from code like this:

> x <- range(..., df$date, ..., na.rm = TRUE)

where the data frame "df" is created by an sqlQuery()-call using RODBC (on
windows), which returns an empty result set.
The data.frame looks like this:

> str(df)
'data.frame':    0 obs. of  2 variables:
 $ id            : Factor w/ 12 levels "IT_001",..:
 $ date    : chr

(Note: first column is forced to be a factor with specific levels using
code not shown.)

> dput(df)
structure(list(tu = structure(integer(0), .Label = c("IT_001", "IT_012"),
class = "factor"),
    id = character(0), date = character(0)), .Names = c("id","date"
), row.names = integer(0), class = "data.frame")

(Note: I edited the output for brevity, hope I didn't break it)

This seems to cause other arguments to be coerced to character:

> range(1:10, df$date, na.rm=TRUE)
[1] "1" "9"

> range(c(as.POSIXct("2014-01-01"), as.POSIXct("2013-01-01")), df$date))
[1] "2013-01-01 CET" "2014-01-01 CET"
> dput(range(c(as.POSIXct("2014-01-01"), as.POSIXct("2013-01-01")),
df$date))
structure(c("1356994800", "1388530800"), class = c("POSIXct",
"POSIXt"))

I would say, RODBC or the layers it's building on, is to blame.


Note that your timezone specification is not atypical for output shorthand
> but may not yield consistent results for input on different OS or locale
> combinations. I think "Etc/GMT-1" or "Europe/Amsterdam" will be more
> reliable depending on your typical data sources.
>

I read these dates from a database and timezones are added by the driver or
db interface layer in R (can't tell which layer is responsible), they are
not present in the database.



> 1k
>

I'm 10k on KGS and 14k on DGS.

Best regards,

Jens

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to