R error: unknown timezone with as.POSIXct()

前端 未结 3 1407
孤街浪徒
孤街浪徒 2020-12-10 00:09

I am trying to convert a unix epoch timestamps to a date-time object using as.POSIXct()

I need to specify timezones (either Europe/London or UTC) when I call as.POSI

相关标签:
3条回答
  • 2020-12-10 00:41

    It does look like you need to update your system with a timezone, even though it isn't being used.

    I can't seem to set my timezone to NA, but if I set my environment with, for example Sys.setenv(TZ='Twilight Zone'), or anything that isn't on the tz list I also get the same errors that you do.

    0 讨论(0)
  • 2020-12-10 00:45

    Looking at the output it is not actually giving a warning about 'Europe/London', just about other variations ('BST' and 'default/Europe/London').

    Could it be that it are errors of previous commands still lingering? Do you get the same if run you the as.POSIXct(1445329330, tz="Europe/London", origin="1970-01-01") again, or even restart R?

    I still get the error about BST even if using the correct timezone

    > as.POSIXct(1445329330, tz="BST", origin="1970-01-01")
    [1] "2015-10-20 08:22:10 GMT"
    Warning message:
    In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'BST'
    > as.POSIXct(1445329330, tz="Europe/London", origin="1970-01-01")
    [1] "2015-10-20 09:22:10 BST"
    Warning message:
    In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'BST'
    
    0 讨论(0)
  • 2020-12-10 00:48

    I am having a similar issue on macOS High Sierra 10.13.1. As soon as, I try to do anything with dates, I get the following error.

    > as.POSIXct("2017-10-01", format = "%Y-%m-%d")
    [1] "2017-10-01 GMT"
    Warning message:
    In strptime(x, format, tz = tz) :
      unknown timezone 'zone/tz/2017c.1.0/zoneinfo/Pacific/Auckland'
    

    The warning goes away if I set the environment variable to my timezone and I get the date back with the correct timezone.

    > Sys.setenv(TZ = "Pacific/Auckland")
    > as.POSIXct("2017-10-01")
    [1] "2017-10-01 NZDT"
    

    So, I have been setting the environment variable every time I need to do something to do with dates.

    However, I have found this link talking about the same thing. Peter Dalgaard from R Core Team has replied saying this was a bug in macOS 10.13 Beta and that it is up to Apple to sort it out.

    I am thinking to put Sys.setenv(TZ = "Pacific/Auckland") into .Rprofile so that it sets the time zone every time I start RStudio. I hope this helps.

    Here is a link that might be useful if you want to try the .Rprofile approach I mentioned.

    Update: It seems like this has been resolved in R 3.4.3. You can read more about it in the R news. Below is the related part of the release notes.

    INSTALLATION on a UNIX-ALIKE

    A workaround has been added for the changes in location of time-zone files in macOS 10.13 'High Sierra' and again in 10.13.1, so the default time zone is deduced correctly from the system setting when R is configured with --with-internal-tzcode (the default on macOS).

    I can confirm that the new version of R resolves the issues with date/time objects.

    > Sys.timezone()
    [1] "Pacific/Auckland"
    > Sys.time()
    [1] "2017-12-30 16:22:32 NZDT"
    
    0 讨论(0)
提交回复
热议问题