开发者

How to disable R warning: timezone of object (UTC) is different than current timezone ()

开发者 https://www.devze.com 2023-02-02 16:51 出处:网络
I keep getting this warning: timezone of object (UTC) is different than current timezone (). My current timezone is \"EET\", as shown by Sys.timezone().

I keep getting this warning: timezone of object (UTC) is different than current timezone (). My current timezone is "EET", as shown by Sys.timezone().

Is there a way to change the R timezone to UTC, instead of it taking the one from my system? Or to disable the warnin开发者_高级运维g?


Try this:

Sys.setenv(TZ = "UTC")


If there is provision for getting a local timezone it is from:

 Sys.timezone()
[1] ""  # So in my case nothing there

And there is no Sys.timezone()<- function

 Sys.time()
[1] "2011-01-06 16:01:10 EST"

But obviously something is to be had. And here is how to convert to another time zone:

 strftime(Sys.time() , tz="UTC")
[1] "2011-01-06 21:02:48"

For further specific advice perhaps if you offered the results of dput() on the object, we would all have access to any necessary attributes to answer further questions.


If you are sure that your code works and other sources of warnings are not likely, then just put the call inside suppressWarnings().

For example,

require(quantmod)
getSymbols("FDX")
suppressWarnings(chartSeries(FDX,theme="white"))


If you work with xts data type (let's call the xts object xts.ts) from the package xts you can use:

tzone(xts.ts) <- "America/Phoenix"


I landed on this page, as I kept getting this exact same warning too when trying to import manager return data from an excel spreadsheet into a data.frame and then converting the data.frame to an xts. Even xts(x = my.data, order.by = my.dates, tz = Sys.timezone()) did not solve it for me, despite my system and the xts having obviously the same time zone!

How did I solve this without tempering with the system?
Very simple.
Instead of constructing my xts with the construct xts(x = my.data, order.by = my.dates) where my.dates look like: 2014-01-31, 2014-02-28, etc... which kept producing the annoying warning, I simply used xts(x = my.data, order.by = as.Date(my.dates))
Solved: no more warning.

0

精彩评论

暂无评论...
验证码 换一张
取 消