rename.corpus: Rename document variables

View source: R/rename.R

rename.corpusR Documentation

Rename document variables

Description

rename() changes the names of individual document variables using new_name = old_name syntax; rename_with() renames columns using a function.

Usage

## S3 method for class 'corpus'
rename(.data, ...)

## S3 method for class 'corpus'
rename_with(.data, .fn, .cols = everything(), ...)

Arguments

.data

a quanteda object with document variables

...

For rename(): <tidy-select> Use new_name = old_name to rename selected variables.

For rename_with(): additional arguments passed onto .fn.

.fn

A function used to transform the selected .cols. Should return a character vector the same length as the input.

.cols

<tidy-select> Columns to rename; defaults to all columns.

Examples

data_corpus_inaugural %>%
  rename(LastName = President) %>%
  summary(n = 5)
data_corpus_inaugural %>%
  rename_with(toupper) %>%
  summary(n = 5)
data_corpus_inaugural %>%
  rename_with(toupper, starts_with("P")) %>%
  summary(n = 5)

quanteda/quanteda.tidy documentation built on April 5, 2025, 2:50 p.m.