[Rd] Sys.timezone (timedatectl) unnecessarily warns loudly

Jan Gorecki j@gorecki @ending from wit@edu@pl
Sun May 6 06:46:09 CEST 2018

Dear R-devels,

timedatectl binary used by Sys.timezone does not always work reliably.
If it doesn't the warning is raised, unnecessarily because later on
Sys.timezone gets timezone successfully from /etc/timezone. This
obviously might not be true for different linux OSes, but it solves
the issue for simple dockerized Ubuntu 16.04.

Current behavior R Under development (unstable) (2018-05-04 r74695) --
"Unsuffered Consequences"

  #Failed to create bus connection: No such file or directory
  #[1] "Etc/UTC"
  #Warning message:
  #In system("timedatectl", intern = TRUE) :
  #  running command 'timedatectl' had status 1

There was small discussion where I initially put comment about it in:

Below patch makes timedatectl call silent, both suppressWarnings and
ignore.stderr are required to deal with R warning, and warning printed
directly to console from timedatectl.

diff --git src/library/base/R/datetime.R src/library/base/R/datetime.R
index 6b34267936..b81c049f3e 100644
--- src/library/base/R/datetime.R
+++ src/library/base/R/datetime.R
@@ -73,7 +73,7 @@ Sys.timezone <- function(location = TRUE)
     ## First try timedatectl: should work on any modern Linux
     ## as part of systemd (and probably nowhere else)
     if (nzchar(Sys.which("timedatectl"))) {
-        inf <- system("timedatectl", intern = TRUE)
+        inf <- suppressWarnings(system("timedatectl", intern = TRUE,
         ## typical format:
         ## "       Time zone: Europe/London (GMT, +0000)"
         ## "       Time zone: Europe/Vienna (CET, +0100)"

Jan Gorecki

More information about the R-devel mailing list