Skip to content

Commit b955f4a

Browse files
author
TysonStanley
committed
Initial commit
0 parents  commit b955f4a

File tree

13 files changed

+879
-0
lines changed

13 files changed

+879
-0
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
^tidyfast\.Rproj$
2+
^\.Rproj\.user$

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# History files
2+
.Rhistory
3+
.Rapp.history
4+
5+
# Session Data files
6+
.RData
7+
8+
# User-specific files
9+
.Ruserdata
10+
11+
# Example code in package build process
12+
*-Ex.R
13+
14+
# Output files from R CMD build
15+
/*.tar.gz
16+
17+
# Output files from R CMD check
18+
/*.Rcheck/
19+
20+
# RStudio files
21+
.Rproj.user/
22+
23+
# produced vignettes
24+
vignettes/*.html
25+
vignettes/*.pdf
26+
27+
# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
28+
.httr-oauth
29+
30+
# knitr and R markdown default cache directories
31+
*_cache/
32+
/cache/
33+
34+
# Temporary files created by R markdown
35+
*.utf8.md
36+
*.knit.md

DESCRIPTION

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Package: tidyfast
2+
Title: Fast Tidying of Data
3+
Version: 0.0.1
4+
Authors@R:
5+
person(given = "Tyson",
6+
family = "Barrett",
7+
role = c("aut", "cre"),
8+
email = "t.barrett@aggiemail.usu.edu",
9+
comment = c(ORCID = "0000-0002-2137-1391"))
10+
Description: Some tidying functions built on data.table
11+
to provide quick and efficient data manipulation.
12+
Imports: data.table
13+
License: GPL-3
14+
Encoding: UTF-8
15+
LazyData: true
16+
RoxygenNote: 6.1.1

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(nest_dt)
4+
export(unnest_dt)
5+
export(unnest_vec_dt)
6+
import(data.table)

R/nest.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#' Fast Nesting
2+
#'
3+
#' Quickly nest data tables.
4+
#'
5+
#' @param dt the data table to nest
6+
#' @param ... the variables to group by
7+
#' @param .key the name of the list column; default is "data"
8+
#'
9+
#' @import data.table
10+
#'
11+
#' @export
12+
nest_dt <- function(dt, ..., .key = "data"){
13+
stopifnot(is.data.table(dt))
14+
15+
by <- substitute(list(...))
16+
17+
dt <- dt[, list(list(.SD)), by = eval(by)]
18+
setnames(dt, old = "V1", new = .key)
19+
dt
20+
}
21+
22+

R/unnest.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#' Fast Unnesting of Data Tables
2+
#'
3+
#' Quickly unnest data tables.
4+
#'
5+
#' @param dt the data table to nest
6+
#' @param col the column to unnest
7+
#' @param id the ID variable to unnest by
8+
#'
9+
#' @import data.table
10+
#'
11+
#' @export
12+
unnest_dt <- function(dt, col, id){
13+
stopifnot(is.data.table(dt))
14+
15+
by <- substitute(id)
16+
col <- substitute(unlist(col, recursive = FALSE))
17+
18+
dt[, eval(col), by = eval(by)]
19+
}
20+
21+
#' Fast Unnesting of Vectors
22+
#'
23+
#' Quickly nest vectors nested in a list column.
24+
#'
25+
#' @param dt the data table to nest
26+
#' @param cols the columns to unnest
27+
#' @param id the ID variable to unnest by
28+
#' @param name the names of the unnested vectors
29+
#'
30+
#' @import data.table
31+
#'
32+
#' @export
33+
unnest_vec_dt <- function(dt, cols, id, name){
34+
stopifnot(is.data.table(dt))
35+
36+
by <- substitute(id)
37+
cols <- substitute(unlist(cols,recursive = FALSE))
38+
39+
dt <- dt[,eval(cols), by = eval(by)]
40+
setnames(dt, old = paste0("V", 1:length(name)), new = name)
41+
dt
42+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# tidyfast
2+

man/nest_dt.Rd

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)