Package 'RApiDatetime'

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-09-06 21:15:10 UTC
Source: https://github.com/eddelbuettel/rapidatetime

Help Index


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.

Package Content

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

Maintainer

Dirk Eddelbuettel <[email protected]>

Author(s)

Dirk Eddelbuettel [aut, cre] (<https://orcid.org/0000-0001-6419-907X>)


Conversion from POSIXct to Date

Description

Conversion from POSIXct to Date

Usage

asDatePOSIXct(x, tz = "")

Arguments

x

A POSIXct vector

tz

An optional timezone string

Details

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.

Value

A vector of Date objects

Author(s)

Joshua Ulrich

Examples

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

R Wrappers for strptime, asPOSIXlt etc

Description

Wrappers for C-level strptime etc functions

Usage

rapistrptime(x, fmt, tz = "")

rapiAsPOSIXlt(x, tz = "")

rapiAsPOSIXct(x, tz = "")

rapiFormatPOSIXlt(x, fmt, usetz = FALSE)

rapiPOSIXlt2D(x)

rapiD2POSIXlt(x)

Arguments

x

Vector with one or character elements to be parsed

fmt

The format string, see help("strptime") for details.

tz

An optional timezone string

usetz

An optional logical variable selecting use of the timezone.

Details

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

Value

A vector with POSIXlt datetime objects

Author(s)

Dirk Eddelbuettel

Examples

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"))