unit_guess {timeplyr}R Documentation

Guess time unit and extract basic information.

Description

This is a simple R function to convert time units to a common unit, with number and scale.
See .time_units for a list of accepted time units.

Usage

unit_guess(x)

Arguments

x

This can be 1 of 4 options:

  • A string, e.g. "7 days"

  • lubridate duration or period object, e.g. days(1) or ddays(1).

  • A list, e.g. list("days" = 7)

  • A number, e.g. 5

Value

A list of length 3, including the unit, number and scale.

Examples

library(timeplyr)

# Single units
unit_guess("days")
unit_guess("hours")

# Multi-units
unit_guess("7 days")
unit_guess("0.5 hours")

# Negative units
unit_guess("-7 days")
unit_guess("-.12 days")

# Exotic units
unit_guess("fortnights")
unit_guess("decades")
.extra_time_units

# list input is accepted
unit_guess(list("months" = 12))
# With a list, a vector of numbers is accepted
unit_guess(list("months" = 1:10))
unit_guess(list("days" = -10:10 %% 7))

# Numbers also accepted
unit_guess(100)


[Package timeplyr version 0.8.1 Index]