Convert ‘YMD’ format number or string to Date efficiently, e.g.,
211225 to as.Date("2021-12-25"), using Rust’s
standard library. It also provides helper functions to handle Date,
e.g., quick finding the beginning or end of the given period, adding
months to Date, etc.
It’s similar to the lubridate package but is much
lighter and focuses only on Date objects.
Installation
Binary version (no
Rust toolchain required)
CRAN provides the binary package. So, if you are on Windows or macOS,
the package can be installed via:
install.packages("ymd")
If you are on Linux, you can try to use the RSPM (RStudio Package Manager)
repo provided by RStudio PBC, via (remember to choose the correct
binary repo URL for your platform):
install.packages("ymd", repos ="{RSPM-Repo-URL}")
Source version (Rust
toolchain required)
If you want to build the dev version from source, you’ll need the
Rust toolchain, which can be installed following the
instructions from the Rust book.
# tweak from https://github.com/Rdatatable/data.table/pull/5300set.seed(373L)x <-as.Date(data.table::as.IDate(sample(seq(-25000, 45000), 1e6, TRUE)))run_bmk( data.table::year(x), lubridate::year(x), funchir::quick_year(x), ymd::year(x))#> Warning: Some expressions had a GC in every iteration; so filtering is#> disabled.
expression
min
median
itr.sec
mem_alloc
gc.sec
n_itr
n_gc
data.table::year(x)
4585.9
5416.8
152.4
7.64MB
37.6
77
19
lubridate::year(x)
294390.5
299745.7
3.3
57.23MB
6.7
2
4
funchir::quick_year(x)
31250.7
31840.8
26.4
26.76MB
7.5
14
4
ymd::year(x)
8761.9
9779.2
100.2
3.82MB
3.9
51
2
run_bmk( data.table::month(x), lubridate::month(x), ymd::month(x))#> Warning: Some expressions had a GC in every iteration; so filtering is#> disabled.
expression
min
median
itr.sec
mem_alloc
gc.sec
n_itr
n_gc
data.table::month(x)
22814.2
24120.2
36.0
7.63MB
6.0
18
3
lubridate::month(x)
291692.5
330627.5
3.0
95.37MB
4.5
2
3
ymd::month(x)
8999.5
9907.7
97.6
3.82MB
8.0
49
4
run_bmk( data.table::quarter(x), lubridate::quarter(x), ymd::quarter(x))#> Warning: Some expressions had a GC in every iteration; so filtering is#> disabled.
expression
min
median
itr.sec
mem_alloc
gc.sec
n_itr
n_gc
data.table::quarter(x)
18667.2
19201.8
51.4
7.63MB
5.9
26
3
lubridate::quarter(x)
295815.7
311213.9
3.2
110.66MB
8.0
2
5
ymd::quarter(x)
16038.6
16756.7
54.4
3.82MB
1.9
28
1
run_bmk( data.table::yday(x), lubridate::yday(x), funchir::quick_yday(x), ymd::yday(x))#> Warning: Some expressions had a GC in every iteration; so filtering is#> disabled.
expression
min
median
itr.sec
mem_alloc
gc.sec
n_itr
n_gc
data.table::yday(x)
8636.1
9384.6
101.1
7.63MB
17.8
51
9
lubridate::yday(x)
256363.1
259132.9
3.9
57.23MB
5.8
2
3
funchir::quick_yday(x)
24603.2
25937.3
37.8
19.08MB
17.9
19
9
ymd::yday(x)
8815.9
9605.1
93.9
3.82MB
4.0
47
2
run_bmk( data.table::mday(x), lubridate::mday(x), funchir::quick_mday(x), ymd::mday(x))#> Warning: Some expressions had a GC in every iteration; so filtering is#> disabled.
run_bmk( data.table::isoweek(x), lubridate::isoweek(x), ymd::isoweek(x))#> Warning: Some expressions had a GC in every iteration; so filtering is#> disabled.