talk_filter: Talk to Filter a Data set

Description Usage Arguments Value Examples

View source: R/talk_filter.R

Description

Talk to Filter a Data set

Usage

1
2
3
4
5
6
7
talk_filter(.data, cmd, verbose = FALSE, ...)

talk_filter_expr(data_colnames, cmd, ...)

talk_process_filter_cmd(cmd)

talk_colnames_class(.data)

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

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
30
31
32
33
34
35
36
library(tibble)
library(dplyr)
df = tibble::rownames_to_column(mtcars, var = "car")
df = df %>%
  rename(cylinders = cyl,
horsepower = hp,
American = am,
carburetor = carb)
cmds = c("subset rows, by horsepower > 100",
        "keep rows where horsepower less than 100",
        "drop rows where American equals 1",
        "drop rows where American is equal to 1",
        "drop rows where American is equal 1",
        "drop values in column 6 not equal to 4",
        "filter out MPG greater than 30",
        "filter the rows where American is not less than or equal 0",
        "return the data with values of cylinders not less than 4",
        "filter where cylinders are not missing",
        "filter if cylinders isn't missing",
        "filter so gear equal 6")
 data_colnames = colnames(df)
 exprs = lapply(cmds, talk_filter_expr, data_colnames = df)
 exprs = sapply(exprs, function(x) x$condition)
 results = lapply(cmds, talk_filter, .data = df)
 cyl = df %>%
 talk_filter("filter if cylinders is equal to 6")
testthat::expect_true(all(cyl$cylinders == 6))
 results = lapply(cmds, talk_filter, .data = df)
cmd = "filter where cylinders are not missing and gear greater than 6"
res = talk_filter_expr(cmd, data_colnames = df)
testthat::expect_true(res$condition == "!is.na(cylinders) & gear > 6")

cmd = "filter where cylinders equal to 4 or gear equals 6"
res = talk_filter_expr(cmd, data_colnames = df)
testthat::expect_true(res$condition == "cylinders == 4 | gear == 6")
talk_colnames_class(cyl)

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