Bug 17421 - Sys.timezone (timedatectl) unnecessarily warns loudly
Summary: Sys.timezone (timedatectl) unnecessarily warns loudly
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R 3.5.0
Hardware: Other Linux
: P5 normal
Assignee: R-core
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-11 05:14 UTC by Jan Gorecki
Modified: 2020-02-02 04:40 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Gorecki 2018-05-11 05:14:49 UTC
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)"

Jan Gorecki
Comment 1 Elin Waring 2020-02-02 04:40:43 UTC
This issue seems to have been resolved on versions above R 3.4.   This is based on an exchange with Jan Gorecki at the github comment in the report.

Seems like this can be closed.