Doing away with “unknown timezone” warnings

November 8, 2011
By

(This article was first published on [R]appster, and kindly contributed to R-bloggers)

Timezone stuff can really drive you NUTS

- at least if you’re sitting in front of a German Windows-Box ;-)

This is what I used to do to set my tz:


options(tz="Europe/Berlin")

And I always wondered why R would throw “unknown timezone” warnings:


> t <- "2011-11-08 09:42:00"
 > as.POSIXct(t, tz=getOption("tz"))
 [1] "2011-11-08 09:42:00 CET"
 Warning messages:
 1: In strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) :
 unknown timezone 'MET-1MST'
 2: In as.POSIXct.POSIXlt(x) : unknown timezone 'MET-1MST'
 3: In strptime(x, f, tz = tz) : unknown timezone 'MET-1MST'
 4: In as.POSIXct.POSIXlt(as.POSIXlt(x, tz, ...), tz, ...) :
 unknown timezone 'MET-1MST'
 5: In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'MET-1MST'

Someday I found out that setting tz via `options()` was not enough as the environment variable `TZ` is not affected and hence all the the trouble:


> Sys.getenv("TZ")
 [1] "MET-1MST"

Changing this should do away with the nasty warnings:


> Sys.setenv(TZ="Europe/Berlin")
 > Sys.getenv("TZ")
 [1] "Europe/Berlin"
 > as.POSIXct(t, tz=getOption("tz"))
 [1] "2011-11-08 09:42:00 CET"


To leave a comment for the author, please follow the link and comment on his blog: [R]appster.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.