:exclamation: This is a read-only mirror of the CRAN R package repository. ymd — Parse 'YMD' Format Number or String to Date. Homepage: https://shrektan.github.io/ymd/, https://github.com/shrektan/ymd Report bugs for this package: https://github.com/shrektan/ymd/issues
License: Other
R 42.24%C 0.56%Rust 55.48%Shell 1.72%
ymd's Introduction
ymd
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/5300
set.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)
4528.2
4988.7
172.0
7.64MB
40.0
86
20
lubridate::year(x)
281901.9
282685.4
3.5
57.23MB
7.1
2
4
funchir::quick_year(x)
30036.8
30385.8
27.7
26.76MB
7.9
14
4
ymd::year(x)
7976.5
8543.1
113.7
3.82MB
6.0
57
3
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)
21728.8
21979.7
44.8
7.63MB
3.9
23
2
lubridate::month(x)
265033.9
267228.5
3.7
95.37MB
3.7
2
2
ymd::month(x)
7696.7
8770.6
111.0
3.82MB
9.9
56
5
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)
17607.5
17977.1
51.1
7.63MB
7.9
26
4
lubridate::quarter(x)
285546.4
289119.8
3.5
110.66MB
3.5
2
2
ymd::quarter(x)
14518.9
15361.2
64.0
3.82MB
4.0
32
2
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.
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.