[Rd] problem running test on a system without /etc/localtime
Dirk Eddelbuettel
edd at debian.org
Wed May 17 04:57:38 CEST 2017
On 17 May 2017 at 03:35, Kirill Maslinsky wrote:
| I'm packaging R for Sisyphus repository and package build environment,
| by design, doesn't have /etc/localtime file present. This causes failure
| with Sys.timeone during test run:
[...]
| It seems that the best solution will be to patch Sys.timezone.
The file-based approach was AFAIK never successfully standardized.
Setting a TZ is a defensible fallback. At some point last year I got so
annoyed about this (and have the historical Debian attitude that a config
file may be preferable to a environment variable [ which I now think is wrong
for some things like TZ ]) I wrote the 'gettz' package. Quick demo in a
Docker container with nothing set:
edd at max:~$ docker run --rm -ti r-base /bin/bash
root at f3848979cab4:/# echo $TZ
echo $TZ
root at f3848979cab4:/# R
R
R version 3.4.0 (2017-04-21) -- "You Stupid Darkness"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> Sys.getenv("TZ") # as expected
Sys.getenv("TZ") # as expected
[1] ""
> install.packages("gettz")
install.packages("gettz")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/gettz_0.0.3.tar.gz'
Content type 'application/x-gzip' length 9064 bytes
==================================================
downloaded 9064 bytes
* installing *source* package ‘gettz’ ...
** package ‘gettz’ successfully unpacked and MD5 sums checked
** libs
g++ -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fdebug-prefix-map=/build/r-base-3.4.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c gettz.cpp -o gettz.o
g++ -shared -L/usr/lib/R/lib -Wl,-z,relro -o gettz.so gettz.o -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/gettz/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (gettz)
The downloaded source packages are in
‘/tmp/RtmpLvuVz8/downloaded_packages’
> gettz::gettz()
gettz::gettz()
[1] "Etc/UTC"
>
As I recall, R got patched for R 3.3.3 or R 3.4.0 to return "" in more cases.
gettz is a little smarter about looking in more locations that R was at the
time (and hence not dissimilar to what was suggested earlier today, but
operates at compiled-code level). It uses a trick I found on StackOverflow
(and which is credited in the package).
It is certainly not perfect, but it is "good enough" for the uses I had in
packages requiring some localtime information.
Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the R-devel
mailing list