Jan Gorecki
2018-May-06 04:46 UTC
[Rd] Sys.timezone (timedatectl) unnecessarily warns loudly
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
Maybe Matching Threads
- Timezone conversion on Ubuntu 20.04
- capture.output(eval(..., envir)) not evaluate in the expected(?) environment
- factors with non-unique ("duplicated") levels have been deprecated since 2009 -- are *more* deprecated now -- and why you should be hesitant misusing suppressWarnings()
- Quantstrat; error with applyStrategy()
- log transform a data frame