Skip to content

Commit 5dc9ba0

Browse files
committed
Add information about updating in tools/
1 parent b0ae341 commit 5dc9ba0

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
^civil\.Rproj$
22
^\.Rproj\.user$
33
^LICENSE\.md$
4+
^tools$

tools/update

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--------------------------------------------------------------------------------
2+
Updating `civil` dependencies
3+
4+
1. Update the version in `update-database.R`.
5+
6+
2. Run `update-database.R` to update `inst/tzdata/` and
7+
`inst/tzdata/windowsZones.xml`.
8+
9+
3. Run `update-date-library.R` to update the headers and `tz.cpp` in `src/`.
10+
11+
4. Go back through `tz.cpp` and comment out all uses to `std::cerr()`, which
12+
R CMD Check doesn't like.

tools/update-database.R

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
library(here)
2+
library(fs)
3+
4+
# Notes about this updater:
5+
#
6+
# Don't forget to update the version below.
7+
#
8+
# This updater will download all the required information and will place it
9+
# in the right place. The next few paragraphs describe what it downloads in
10+
# case you have to do it manually for some reason.
11+
#
12+
# The time zone database is downloaded from: https://www.iana.org/time-zones.
13+
# If you are going to do it manually for some reason, choose the latest
14+
# version, and grab the one with JUST the data, in the format like
15+
# `tzdata2019c.tar.gz`. Uncompress it, and then take the contents of the
16+
# folder and move them into `inst/tzdata/`.
17+
#
18+
# On Windows, we also need a `windowsZone.xml` mapping file.
19+
# It can be found here if you need to download it manually:
20+
# https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml.
21+
# Download this file and place it in `inst/tzdata` as `windowsZones.xml`.
22+
23+
# Update the version!
24+
version <- "2020d"
25+
26+
# ------------------------------------------------------------------------------
27+
# Download the time zone database
28+
29+
file <- paste0("tzdata", version, ".tar.gz")
30+
31+
path_base <- "https://data.iana.org/time-zones/releases/"
32+
path_version <- path(path_base, file)
33+
34+
dir_temp <- tempdir()
35+
path_temp <- tempfile(fileext = ".tar.gz", tmpdir = dir_temp)
36+
37+
download.file(path_version, path_temp)
38+
39+
untar(path_temp, exdir = here("inst", "tzdata"))
40+
41+
unlink(path_temp)
42+
unlink(dir_temp, recursive = TRUE, force = TRUE)
43+
44+
# ------------------------------------------------------------------------------
45+
# Download the Windows mapping file
46+
47+
windows_mapping_url <- "https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/windowsZones.xml"
48+
path_dest_windows_mapping <- here("inst/tzdata/windowsZones.xml")
49+
50+
download.file(windows_mapping_url, path_dest_windows_mapping)

tools/update-date-library.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
library(here)
2+
library(fs)
3+
library(glue)
4+
5+
# Notes about this updater:
6+
#
7+
# The `tz.cpp` file that is downloaded into `src/tz.cpp` will need to be updated
8+
# to pass R CMD Check. All calls to `std::cerr` will have to be commented out.
9+
10+
# ------------------------------------------------------------------------------
11+
# cd into temp dir
12+
# git clone the repo
13+
14+
dir_temp <- tempdir()
15+
dir_dest <- dir_create(path(dir_temp, "dest/"))
16+
17+
url_repo <- "https://github.com/HowardHinnant/date"
18+
19+
cmd_cd <- glue(shQuote("cd"), " ", dir_dest)
20+
cmd_clone <- glue(shQuote("git"), " clone ", url_repo)
21+
cmd <- glue(cmd_cd, "; ", cmd_clone)
22+
23+
# cd into temp dir
24+
# git clone the repo
25+
system(cmd)
26+
27+
dir_date <- path(dir_dest, "date")
28+
29+
# ------------------------------------------------------------------------------
30+
# Update headers and tz.cpp
31+
# Will overwrite src/tz.cpp (which will need to be tweaked)
32+
33+
dir_src <- here("src")
34+
35+
dir_date_include_date <- path(dir_date, "include", "date")
36+
dir_copy(dir_date_include_date, dir_src, overwrite = TRUE)
37+
38+
file_date_src_tz <- path(dir_date, "src", "tz.cpp")
39+
file_pkg_src_tz <- path(dir_src, "tz.cpp")
40+
41+
file_copy(file_date_src_tz, file_pkg_src_tz, overwrite = TRUE)
42+
43+
# ------------------------------------------------------------------------------
44+
45+
unlink(dir_temp, recursive = TRUE, force = TRUE)

0 commit comments

Comments
 (0)