talk_replace: Talk to Replace all types a Data set

Description Usage Arguments Value Examples

View source: R/talk_replace_all.R

Description

Talk to Replace all types a Data set

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
talk_replace(.data, cmd, verbose = FALSE, ...)

talk_replace_expr(
  data_colnames,
  cmd,
  allowed_words = c("factor", "logical", "numeric", "character", "double"),
  ...
)

talk_process_replace_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
library(tibble)
library(dplyr)
df = mtcars %>%
  rownames_to_column(var = "car")
  cmds = c(
    "replace gear mpg as factors",
    "replace car as factor",
    "replace gear as character")
 data_colnames = df
 .data = df
 cmd = cmds[1]
 results = lapply(cmds, talk_replace, .data = df)
 testthat::expect_warning(talk_replace(.data, cmd),
 "allowed")
df = df %>%
  rename(GEAR = gear)
 gear = df %>%
 talk_replace("replace by gear and column 3 as factors")
 d_classes = sapply(gear[, c("cyl", "GEAR")], class)
testthat::expect_true(all(d_classes == "factor"))

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