-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathREADME.Rmd
85 lines (64 loc) · 2.66 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
output:
downlit::readme_document:
html_preview: false
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
pkgload::load_all()
```
# hms <a href='https:/hms.tidyverse.org'><img src='man/figures/logo.png' align="right" height="139" /></a>
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![rcc](https://github.com/tidyverse/hms/workflows/rcc/badge.svg)](https://github.com/tidyverse/hms/actions)
[![Codecov test coverage](https://codecov.io/gh/tidyverse/hms/branch/main/graph/badge.svg)](https://app.codecov.io/gh/tidyverse/hms?branch=main)
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/hms)](https://cran.r-project.org/package=hms)
<!-- badges: end -->
## Overview
The hms package provides a simple class for storing durations or time-of-day values and displaying them in the hh:mm:ss format. This class is intended to simplify data exchange with databases, spreadsheets, and other data sources:
- Stores values as a numeric vector that contains the number of seconds
since midnight
- Supports construction from explicit hour, minute, or second values
- Supports coercion to and from various data types, including `POSIXt`
- Can be used as column in a data frame
- Based on the `difftime` class
- Values can exceed the 24-hour boundary or be negative
- By default, fractional seconds up to a microsecond are displayed, regardless of the value of the `"digits.secs"` option
## Installation
```r
# The easiest way to get hms is to install the whole tidyverse:
install.packages("tidyverse")
# Alternatively, install just hms:
install.packages("hms")
# Or the the development version from GitHub:
# install.packages("devtools")
devtools::install_github("tidyverse/hms")
```
## Usage
The following example showcases ways of using the `hms` class standalone or as a data frame column.
```{r}
library(hms)
hms(56, 34, 12)
as_hms(Sys.time())
parse_hms("12:34:56")
as.POSIXct(hms(1))
data.frame(hours = 1:3, hms = hms(hours = 1:3))
```
## Internal representation
Objects of the `hms` and its underlying `difftime` classes are stored as number of seconds since `00:00:00`.
Use `as.numeric()` and `as_hms()` to convert to and from numbers.
```{r}
times <- parse_hms(c("00:00:00.25", "00:00:01", "00:01:30", "01:00:00"))
times
times_num <- as.numeric(times)
times_num
as_hms(times_num)
```
---
Please note that the 'hms' project is released with a
[Contributor Code of Conduct](https://github.com/tidyverse/hms/blob/master/CODE_OF_CONDUCT.md).
By contributing to this project, you agree to abide by its terms.