Datetime2Time: Convert Datetime columns to Time columns

View source: R/Datetime2Time.R

Datetime2TimeR Documentation

Convert Datetime columns to Time columns

Description

Convert Datetime columns to Time columns

Usage

Datetime2Time(
  dataset,
  cols = dplyr::where(lubridate::is.POSIXct),
  silent = FALSE
)

Arguments

dataset

A data.frame with POSIXct columns.

cols

The column names to convert. Expects a symbol. The default will convert all POSIXct columns. If uncertain whether columns exist in the dataset, use dplyr::any_of().

silent

Logical on whether no message shall be shown if input and output are identical. Defaults to FALSE (i.e., a message is shown).

Value

The input dataset with converted POSIXct columns as time (hms) columns. With the default settings, if no POSIXct column exists, input and output will be identical.

Examples

sample.data.environment |> Datetime2Time()
#more than one POSIX col
sample.data.environment |>
  dplyr::mutate(Datetime2 = lubridate::POSIXct(1)) |>
  Datetime2Time()
#only converting one of them
sample.data.environment |>
  dplyr::mutate(Datetime2 = lubridate::POSIXct(1)) |>
  Datetime2Time(Datetime)
#if uncertain whether column exists
sample.data.environment |>
  Datetime2Time(dplyr::any_of("Datetime3"))

LightLogR documentation built on June 10, 2025, 5:12 p.m.