Title: | R API for 'Date' and 'Datetime' |
---|---|
Description: | Access to the C-level R date and 'datetime' code is provided for C-level API use by other packages via registration of native functions. Client packages simply include a single header 'RApiDatetime.h' provided by this package, and also 'import' it. The R Core group is the original author of the code made available with slight modifications by this package. |
Authors: | Dirk Eddelbuettel [aut, cre] |
Maintainer: | Dirk Eddelbuettel <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.9 |
Built: | 2024-11-05 04:57:02 UTC |
Source: | https://github.com/eddelbuettel/rapidatetime |
Access to the C-level R date and 'datetime' code is provided for C-level API use by other packages via registration of native functions. Client packages simply include a single header 'RApiDatetime.h' provided by this package, and also 'import' it. The R Core group is the original author of the code made available with slight modifications by this package.
Index of help topics:
RApiDatetime-package R API for 'Date' and 'Datetime' asDatePOSIXct Conversion from POSIXct to Date rapistrptime R Wrappers for 'strptime', 'asPOSIXlt' etc
Dirk Eddelbuettel <[email protected]>
Dirk Eddelbuettel [aut, cre] (<https://orcid.org/0000-0001-6419-907X>)
Conversion from POSIXct to Date
asDatePOSIXct(x, tz = "")
asDatePOSIXct(x, tz = "")
x |
A POSIXct vector |
tz |
An optional timezone string |
This function provides a direct conversion from POSIXct to Date. As of R-3.5.1, conversion from POSIXct to Date creates an intermediate POSIXlt object. This intermediate POSIXlt object uses a non-trivial amount of memory. The direct conversion is more memory efficient, and therefore approximately twice as fast as the current solution in base R.
A vector of Date
objects
Joshua Ulrich
p <- .POSIXct(1540181413, "America/Chicago") as.Date(p) # Using UTC timezone as.Date(p, "America/Chicago") # Using local timezone asDatePOSIXct(p) # Direct, using local timezone
p <- .POSIXct(1540181413, "America/Chicago") as.Date(p) # Using UTC timezone as.Date(p, "America/Chicago") # Using local timezone asDatePOSIXct(p) # Direct, using local timezone
strptime
, asPOSIXlt
etcWrappers for C-level strptime
etc functions
rapistrptime(x, fmt, tz = "") rapiAsPOSIXlt(x, tz = "") rapiAsPOSIXct(x, tz = "") rapiFormatPOSIXlt(x, fmt, usetz = FALSE) rapiPOSIXlt2D(x) rapiD2POSIXlt(x)
rapistrptime(x, fmt, tz = "") rapiAsPOSIXlt(x, tz = "") rapiAsPOSIXct(x, tz = "") rapiFormatPOSIXlt(x, fmt, usetz = FALSE) rapiPOSIXlt2D(x) rapiD2POSIXlt(x)
x |
Vector with one or character elements to be parsed |
fmt |
The format string, see |
tz |
An optional timezone string |
usetz |
An optional logical variable selecting use of the timezone. |
These functions provide (additional) entry points from R to the C-level function of the R API. They are provided here mainly for testing (the C level access) as R itself exposes the function
A vector with POSIXlt
datetime objects
Dirk Eddelbuettel
op <- options(digits.secs=6) x <- rapistrptime("2017-01-02 03:04:05.678", "%Y-%m-%d %H:%M:%OS") format(x) rapiAsPOSIXlt(as.POSIXct(x)) rapiAsPOSIXct(x) rapiFormatPOSIXlt(x, "%Y-%b-%d %H:%M:%OS") options(op) rapiPOSIXlt2D(x) rapiD2POSIXlt(as.Date("2017-01-02"))
op <- options(digits.secs=6) x <- rapistrptime("2017-01-02 03:04:05.678", "%Y-%m-%d %H:%M:%OS") format(x) rapiAsPOSIXlt(as.POSIXct(x)) rapiAsPOSIXct(x) rapiFormatPOSIXlt(x, "%Y-%b-%d %H:%M:%OS") options(op) rapiPOSIXlt2D(x) rapiD2POSIXlt(as.Date("2017-01-02"))