Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace magrittr pipe with base R pipe #23

Merged
merged 15 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export("%gin%")
export(br)
export(ftab)
export(ta)
export(tab)
export(tab1)
export(tab2)
importFrom(magrittr,"%>%")
importFrom(rlang,"%|%")
importFrom(rlang,":=")
importFrom(rlang,.data)
16 changes: 8 additions & 8 deletions R/tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,31 @@
#'
#' @examples
#' # one-way table of frequencies
#' mtcars %>% tab(cyl)
#' mtcars |> tab(cyl)
#'
#' # two-way table of frequencies (a special 2x2 contingency table)
#' mtcars %>% tab(cyl, gear)
#' mtcars |> tab(cyl, gear)
#'
#' # flat contingency tables of three (or more) variables
#' mtcars %>% tab(cyl, gear, am)
#' mtcars |> tab(cyl, gear, am)
#'
#' # tables wider than the R console are automatically wrapped
#' mtcars %>% tab(cyl, gear, am, vs)
#' mtcars |> tab(cyl, gear, am, vs)
#'
#' # missing values are displayed in red
#' tab(letters[24:27])
#'
#' # ftab() displays only flat contingency tables (here, with two variables)
#' mtcars %>% ftab(cyl, gear)
#' mtcars |> ftab(cyl, gear)
#'
#' # tab1() displays one-way tables for each variable
#' mtcars %>% tab1(cyl, gear)
#' mtcars |> tab1(cyl, gear)
#'
#' # tab2() displays two-way tables for all variable combinations
#' mtcars %>% tab2(cyl, gear, am)
#' mtcars |> tab2(cyl, gear, am)
#'
#' # ta() is a shortened alias for tab(), inspired by Stata
#' mtcars %>% ta(gear)
#' mtcars |> ta(gear)
#'
#' @aliases
#' ta
Expand Down
11 changes: 0 additions & 11 deletions R/utils-pipe.R

This file was deleted.

16 changes: 8 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ devtools::install_github("gvelasq/tidytab")
library(tidytab)

# one-way table of frequencies
mtcars %>% tab(cyl)
mtcars |> tab(cyl)
gvelasq marked this conversation as resolved.
Show resolved Hide resolved

# two-way table of frequencies (a special 2x2 contingency table)
mtcars %>% tab(cyl, gear)
mtcars |> tab(cyl, gear)

# flat contingency tables of three (or more) variables
mtcars %>% tab(cyl, gear, am)
mtcars |> tab(cyl, gear, am)

# tables wider than the R console are automatically wrapped
mtcars %>% tab(cyl, gear, am, vs)
mtcars |> tab(cyl, gear, am, vs)

# missing values are displayed in red
tab(letters[24:27])

# ftab() displays only flat contingency tables (here, with two variables)
mtcars %>% ftab(cyl, gear)
mtcars |> ftab(cyl, gear)

# tab1() displays one-way tables for each variable
mtcars %>% tab1(cyl, gear)
mtcars |> tab1(cyl, gear)

# tab2() displays two-way tables for all variable combinations
mtcars %>% tab2(cyl, gear, am)
mtcars |> tab2(cyl, gear, am)

# ta() is a shortened alias for tab(), inspired by Stata
mtcars %>% ta(gear)
mtcars |> ta(gear)
```

## Code of Conduct
Expand Down
128 changes: 64 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ devtools::install_github("gvelasq/tidytab")
library(tidytab)

# one-way table of frequencies
mtcars %>% tab(cyl)
mtcars |> tab(cyl)
#> cyl │ Freq. Percent Cum.
#> ────────────┼───────────────────────────────────
#> 4 │ 11 34.4 34.4
#> 6 │ 7 21.9 56.3
#> 8 │ 14 43.8 100.0
#> 4 │ 11 34.38 34.38
gvelasq marked this conversation as resolved.
Show resolved Hide resolved
#> 6 │ 7 21.88 56.25
#> 8 │ 14 43.75 100.0
#> ────────────┼───────────────────────────────────
#> Total │ 32 100.0  

# two-way table of frequencies (a special 2x2 contingency table)
mtcars %>% tab(cyl, gear)
mtcars |> tab(cyl, gear)
#> │ gear │
#> cyl │ 3 4 5 │ Total
#> ───────────┼─────────────────────────────────┼──────────
Expand All @@ -55,102 +55,102 @@ mtcars %>% tab(cyl, gear)
#> Total │ 15 12 5 │ 32

# flat contingency tables of three (or more) variables
mtcars %>% tab(cyl, gear, am)
mtcars |> tab(cyl, gear, am)
#> cyl │ gear am Freq. Percent Cum.
#> ────────────┼───────────────────────────────────────────────────────────
#> 4 │ 3 0 1 3.1 3.1
#> 4 │ 4 0 2 6.2 9.3
#> 4 │ 4 1 6 18.8 28.1
#> 4 │ 5 1 2 6.2 34.3
#> 4 │ 3 0 1 3.12 3.12
#> 4 │ 4 0 2 6.25 9.38
#> 4 │ 4 1 6 18.75 28.12
#> 4 │ 5 1 2 6.25 34.38
#> ------------┼-----------------------------------------------------------
#> 6 │ 3 0 2 6.2 40.5
#> 6 │ 4 0 2 6.2 46.7
#> 6 │ 4 1 2 6.2 52.9
#> 6 │ 5 1 1 3.1 56.0
#> 6 │ 3 0 2 6.25 40.62
#> 6 │ 4 0 2 6.25 46.88
#> 6 │ 4 1 2 6.25 53.12
#> 6 │ 5 1 1 3.12 56.25
#> ------------┼-----------------------------------------------------------
#> 8 │ 3 0 12 37.5 93.5
#> 8 │ 5 1 2 6.2 99.7
#> 8 │ 3 0 12 37.50 93.75
#> 8 │ 5 1 2 6.25 100.00

# tables wider than the R console are automatically wrapped
mtcars %>% tab(cyl, gear, am, vs)
mtcars |> tab(cyl, gear, am, vs)
#> cyl │ gear am vs Freq. Percent
#> ────────────┼───────────────────────────────────────────────────────────
#> 4 │ 3 0 1 1 3.1
#> 4 │ 4 0 1 2 6.2
#> 4 │ 4 1 1 6 18.8
#> 4 │ 5 1 0 1 3.1
#> 4 │ 5 1 1 1 3.1
#> 4 │ 3 0 1 1 3.12
#> 4 │ 4 0 1 2 6.25
#> 4 │ 4 1 1 6 18.75
#> 4 │ 5 1 0 1 3.12
#> 4 │ 5 1 1 1 3.12
#> ------------┼-----------------------------------------------------------
#> 6 │ 3 0 1 2 6.2
#> 6 │ 4 0 1 2 6.2
#> 6 │ 4 1 0 2 6.2
#> 6 │ 5 1 0 1 3.1
#> 6 │ 3 0 1 2 6.25
#> 6 │ 4 0 1 2 6.25
#> 6 │ 4 1 0 2 6.25
#> 6 │ 5 1 0 1 3.12
#> ------------┼-----------------------------------------------------------
#> 8 │ 3 0 0 12 37.5
#> 8 │ 5 1 0 2 6.2
#> 8 │ 3 0 0 12 37.50
#> 8 │ 5 1 0 2 6.25
#>
#> cyl │ Cum.
#> ────────────┼────────────
#> 4 │ 3.1
#> 4 │ 9.3
#> 4 │ 28.1
#> 4 │ 31.2
#> 4 │ 34.3
#> 4 │ 3.12
#> 4 │ 9.38
#> 4 │ 28.12
#> 4 │ 31.25
#> 4 │ 34.38
#> ------------┼------------
#> 6 │ 40.5
#> 6 │ 46.7
#> 6 │ 52.9
#> 6 │ 56.0
#> 6 │ 40.62
#> 6 │ 46.88
#> 6 │ 53.12
#> 6 │ 56.25
#> ------------┼------------
#> 8 │ 93.5
#> 8 │ 99.7
#> 8 │ 93.75
#> 8 │ 100.00

# missing values are displayed in red
tab(letters[24:27])
#> letters[24:27] │ Freq. Percent Cum.
#> ─────────────────┼───────────────────────────────────
#> x │ 1 25.0 25.0
#> y │ 1 25.0 50.0
#> z │ 1 25.0 75.0
#> NA │ 1 25.0 100.0
#> x │ 1 25.00 25.00
#> y │ 1 25.00 50.00
#> z │ 1 25.00 75.00
#> NA │ 1 25.00 100.0
#> ─────────────────┼───────────────────────────────────
#> Total │ 4 100.0  

# ftab() displays only flat contingency tables (here, with two variables)
mtcars %>% ftab(cyl, gear)
mtcars |> ftab(cyl, gear)
#> cyl │ gear Freq. Percent Cum.
#> ────────────┼───────────────────────────────────────────────
#> 4 │ 3 1 3.1 3.1
#> 4 │ 4 8 25.0 28.1
#> 4 │ 5 2 6.2 34.3
#> 4 │ 3 1 3.12 3.12
#> 4 │ 4 8 25.00 28.12
#> 4 │ 5 2 6.25 34.38
#> ------------┼-----------------------------------------------
#> 6 │ 3 2 6.2 40.5
#> 6 │ 4 4 12.5 53.0
#> 6 │ 5 1 3.1 56.1
#> 6 │ 3 2 6.25 40.62
#> 6 │ 4 4 12.50 53.12
#> 6 │ 5 1 3.12 56.25
#> ------------┼-----------------------------------------------
#> 8 │ 3 12 37.5 93.6
#> 8 │ 5 2 6.2 99.8
#> 8 │ 3 12 37.50 93.75
#> 8 │ 5 2 6.25 100.00

# tab1() displays one-way tables for each variable
mtcars %>% tab1(cyl, gear)
mtcars |> tab1(cyl, gear)
#> cyl │ Freq. Percent Cum.
#> ────────────┼───────────────────────────────────
#> 4 │ 11 34.4 34.4
#> 6 │ 7 21.9 56.3
#> 8 │ 14 43.8 100.0
#> 4 │ 11 34.38 34.38
#> 6 │ 7 21.88 56.25
#> 8 │ 14 43.75 100.0
#> ────────────┼───────────────────────────────────
#> Total │ 32 100.0  
#>
#> gear │ Freq. Percent Cum.
#> ────────────┼───────────────────────────────────
#> 3 │ 15 46.9 46.9
#> 4 │ 12 37.5 84.4
#> 5 │ 5 15.6 100.0
#> 3 │ 15 46.88 46.88
#> 4 │ 12 37.50 84.38
#> 5 │ 5 15.62 100.0
#> ────────────┼───────────────────────────────────
#> Total │ 32 100.0  

# tab2() displays two-way tables for all variable combinations
mtcars %>% tab2(cyl, gear, am)
mtcars |> tab2(cyl, gear, am)
#> │ gear │
#> cyl │ 3 4 5 │ Total
#> ───────────┼─────────────────────────────────┼──────────
Expand Down Expand Up @@ -179,12 +179,12 @@ mtcars %>% tab2(cyl, gear, am)
#> Total │ 19 13 │ 32

# ta() is a shortened alias for tab(), inspired by Stata
mtcars %>% ta(gear)
mtcars |> ta(gear)
#> gear │ Freq. Percent Cum.
#> ────────────┼───────────────────────────────────
#> 3 │ 15 46.9 46.9
#> 4 │ 12 37.5 84.4
#> 5 │ 5 15.6 100.0
#> 3 │ 15 46.88 46.88
#> 4 │ 12 37.50 84.38
#> 5 │ 5 15.62 100.0
#> ────────────┼───────────────────────────────────
#> Total │ 32 100.0  
```
Expand Down
12 changes: 0 additions & 12 deletions man/pipe.Rd

This file was deleted.

16 changes: 8 additions & 8 deletions man/tab.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading