-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
110 lines (87 loc) · 2.77 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# timbr
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/timbr)](https://CRAN.R-project.org/package=timbr)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[![Codecov test coverage](https://codecov.io/gh/UchidaMizuki/timbr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/UchidaMizuki/timbr?branch=main)
[![R-CMD-check](https://github.com/UchidaMizuki/timbr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/UchidaMizuki/timbr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
timbr provides data frames for forest or tree data structures.
You can create forest data structures from data frames and process them based on their hierarchies.
## Installation
You can install the development version of timbr from [GitHub](https://github.com/) with:
``` r
# the released version from CRAN:
install.packages("timbr")
# the development version from GitHub:
# install.packages("devtools")
devtools::install_github("UchidaMizuki/timbr")
```
## Main Functions
The main functions provided by timbr are as follows,
- `children()`
- `climb()`
- `leaves()`
- `traverse()`
- `rbind()`
## tidyverse methods
timbr provides some tidyverse methods as follows,
- `mutate()`
- `summarise()`
- `select()` and `relocate()`
- `rows_update()` and `rows_patch()`
## Examples
```{r,warning=FALSE,message=FALSE}
library(timbr)
library(dplyr)
```
```{r}
fr <- tidyr::expand_grid(key1 = letters[1:2],
key2 = letters[1:2],
key3 = letters[1:2]) |>
mutate(value = row_number()) |>
forest_by(key1, key2, key3)
fr_sum <- fr |>
summarise(value = sum(value)) |>
summarise(value = sum(value))
fr
fr_sum
children(fr_sum)
fr_sum |>
climb(key3)
```
```{r}
fr1 <- tidyr::expand_grid(key1 = letters[1:2],
key2_1 = letters[1:2],
key3_1 = letters[1:2]) |>
mutate(value = row_number()) |>
forest_by(key1, key2_1, key3_1) |>
summarise(value = sum(value))
fr2 <- tidyr::expand_grid(key1 = letters[1:2],
key2_2 = letters[1:2],
key3_2 = letters[1:2]) |>
mutate(value = row_number()) |>
forest_by(key1, key2_2, key3_2) |>
summarise(value = sum(value))
fr <- rbind(fr1, fr2)
fr_sum <- fr |>
summarise(value = sum(value))
fr
fr_sum
traverse(fr_sum,
function(x, children) {
x$value <- prod(children$value)
x
})
```