talk_group_by: Talk to Group a Data set

Description Usage Arguments Value Examples

View source: R/talk_group_by.R

Description

Talk to Group a Data set

Usage

1
2
3
4
5
talk_group_by(.data, cmd, verbose = FALSE, ...)

talk_group_by_expr(data_colnames, cmd, allowed_words = "", ...)

talk_process_group_by_cmd(cmd)

Arguments

.data

The data set/data.frame to perform the operation.

cmd

Command to perform on the data set.

verbose

print diagnostic output

...

additional arguments to pass to talk_get_colnames

data_colnames

column names of the data

allowed_words

words allowed to be in the command other than the column names

Value

A data.frame or list of them if length(cmds) > 1.

Examples

 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
library(tibble)
library(dplyr)
df = mtcars %>%
  rownames_to_column(var = "car")
  cmds = c(
    "group by  mpg",
    "Group by  column    mpg  ",
    "group by column 5",
    "arrange by gear",
    "group by columns 4 and 5",
    "group by columns 4 and 5, mpg",
    # duplciate
    "group by columns 2 and 5, mpg",
    "group by columns 4, 5, and 6",
    "group by mpg descending",
    "group by mpg",
    "group by mpg",
    "group by mpg low to high")
 data_colnames = df
 .data = df
 results = lapply(cmds, talk_group_by, .data = df)
 cmd =  "group by columns 2 and 5, mpg decreasing"
 testthat::expect_warning(talk_group_by(.data, cmd),
 "allowed")
df = df %>%
  rename(GEAR = gear)
 gear = df %>%
 talk_group_by("arrange by gear and column 3")
testthat::expect_true(all(group_vars(gear) == c("GEAR", "cyl")))

muschellij2/talkr documentation built on Jan. 20, 2020, 7:49 p.m.