From j@gorecki @ending from wit@edu@pl  Sun May  6 06:46:09 2018
From: j@gorecki @ending from wit@edu@pl (Jan Gorecki)
Date: Sun, 6 May 2018 10:16:09 +0530
Subject: [Rd] Sys.timezone (timedatectl) unnecessarily warns loudly
Message-ID: <CAOO9MKVAYTOVZ+h=zG6nUGdv4uHwa5aAnsCzCkuthGKgc_rEuw@mail.gmail.com>

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"

  Sys.timezone()
  #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:
https://github.com/wch/r-source/commit/9866ac2ad1e2f1c4565ae829ba33b5b98a08d10d#r28867164

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,
ignore.stderr=TRUE))
         ## typical format:
         ## "       Time zone: Europe/London (GMT, +0000)"
         ## "       Time zone: Europe/Vienna (CET, +0100)"

Regards,
Jan Gorecki



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