[Rd] tweaking Sys.timezone()

Serguei Sokol sokol at insa-toulouse.fr
Tue May 16 12:58:00 CEST 2017


On my system (Linux, Mageia 5) Sys.timezone() returns NA but
with a minor tweak it could work as expected, i.e. returning "Europe/Paris".

Here is the problem. At some moment it does

  lt <- normalizePath("/etc/localtime")

On my system /etc/localtime is a symlink pointing to
/usr/share/zoneinfo/Europe/Paris. So far so good.
With the next two operations the good answer should be found:

  if (grepl(pat <- "^/usr/share/zoneinfo/", lt)) sub(pat, "", lt)

Unfortunately, on my system "/usr/share" is also a simlink
so lt resolves to "/home/local/usr_share/zoneinfo/Europe/Paris"
and not to "/usr/share/zoneinfo/Europe/Paris".
So the test above fails.
As the keyword in this story is zoneinfo, could we modify the
pat to look as

   if (grepl(pat <- "^.*/zoneinfo/", lt)) sub(pat, "", lt)

In this way, we don't make assumption where exactly
"zoneinfo/*" resides. We have found it, no matter where, so use it.

Hoping it could find its way into a next R release.


More information about the R-devel mailing list