rk.lubridate: Date & Time Tools for RKWard
This package provides a suite of RKWard plugins that create a graphical user interface for the lubridate R package. It simplifies working with dates and times by providing tools for parsing, formatting, arithmetic, and interval analysis without memorizing format codes or function names.
Features / Included Plugins
This package installs a new submenu in RKWard: Data > Date and Time (lubridate).
Core Tools
-
Parse Date-Times: Convert strings (e.g., "2023/01/15") into R Date objects using intuitive "Orders" (ymd, mdy, dmy_hms).
-
Format Dates as Text: Convert dates back into text strings with presets (e.g., "Friday, November 21") or custom format codes.
-
Get/Set Components: Extract or modify specific parts of a date (Year, Month, Weekday, etc.).
-
Round Date-Times: Round dates to the nearest minute, hour, month, or custom unit.
-
Time Zones: Convert time zones (
with_tz) or fix incorrect time zones (force_tz).
Time Spans
-
Create Periods: Human-readable time spans (e.g., "1 Month") that account for leap years/days.
-
Create Durations: Exact time spans in seconds (e.g., "30 Days" = 2592000s).
-
Create Intervals: Define a span of time between a Start Date and End Date.
Calculations
-
Shift Dates: Add or subtract time from a date (e.g., Date + 2 Months).
-
Check Overlaps: Check if a date falls inside a specific interval (
%within%).
-
Align Dates: "Rollback" dates to the last day of the previous month, or find the start/end of a month.
-
Advanced Extractions: Extract Business quarters, semesters, days of the year, or check for Leap Years.
-
Decimal Conversion: Convert dates to decimal years (2023.5) for regression analysis.
π Internationalization
As of version 0.0.5, the interface is fully localized to match your RKWard language settings:
- πΊπΈ English (Default)
- πͺπΈ Spanish (
es)
- π«π· French (
fr)
- π©πͺ German (
de)
- π§π· Portuguese (Brazil) (
pt_BR)
Requirements
- A working installation of RKWard.
- The R package
lubridate.
install.packages("lubridate")
- The R package
devtools (for installation from source).
Installation
- Open R in RKWard.
- Run the following commands in the R console:
local({
require(devtools)
install_github("AlfCano/rk.lubridate", force = TRUE)
})
- Restart RKWard to ensure the new menu items appear correctly.
Usage & Examples
To test the calculation plugins, create the test_dates dataframe using the code below:
library(lubridate)
ref_int <- interval(ymd("2023-01-01"), ymd("2023-03-31"))
test_dates <- data.frame(
id = 1:5,
event_date = as.Date(c("2023-01-15", "2023-02-28", "2023-03-31", "2024-02-29", "2025-12-25")),
q1_2023 = rep(ref_int, 5)
)
Example 1: Shift Dates (Add 1 Month)
- Navigate to Data > Date and Time (lubridate) > Calculations > Shift Dates.
-
Select Date Object:
test_dates$event_date.
-
Operation: Add (+).
-
Amount: 1.
-
Unit: Months.
-
Time Type: Period.
- Click Submit.
-
Result: Jan 15 becomes Feb 15. Feb 28 becomes Mar 28.
Example 2: Check Overlaps
- Navigate to Data > Date and Time (lubridate) > Calculations > Check Overlaps.
-
Date Object:
test_dates$event_date.
-
Interval Object:
test_dates$q1_2023.
- Click Submit.
-
Result: Returns
TRUE for the dates in Jan, Feb, Mar 2023. Returns FALSE for 2024 and 2025.
Example 3: Align Dates (Rollback)
- Navigate to Data > Date and Time (lubridate) > Calculations > Align Dates.
-
Date Object:
test_dates$event_date.
-
Action: Rollback (Last day of prev month).
- Click Submit.
-
Result: "2023-01-15" becomes "2022-12-31". Useful for aligning financial reports.
Author
Alfonso Cano Robles (alfonso.cano@correo.buap.mx)
Assisted by Gemini, a large language model from Google.