keyboardize_punctuation: Keyboardize punctuation marks

Description Usage Arguments Details Value Examples

View source: R/keyboardize_punctuation.R

Description

Takes a dataset and, for all categories in factor variables, standardizes stylized typographic characters to ASCII versions that are easily typeable on a keyboard.

Usage

1
keyboardize_punctuation(df, convert_characters = FALSE)

Arguments

df

A data.frame.

convert_characters

Should variables of class character also be converted, in addition to variables of class "factor"? Defaults to FALSE.

Details

Text labels in datasets occasionally contain characters not easily typeable on a standard keyboard which are almost impossible to distinguish from keyboard characters. (This often happens when pasting text in from Microsoft Word). These include the curly apostrophe, the en-dash, the em-dash and the ellipsis. This function converts these typographic characters to characters that are on keyboards by default: the single straight apostrophe, the hyphen-minus, and three periods.

Value

A copy of the original data.frame, with nonstandard characters replaced.

Examples

1
2
3
4
5
6
7
8
library(dplyr)
# Create an unwanted factor label containing a stylized apostrophe ’ for illustration.
dec13_excerpt <- dec13_excerpt %>% mutate(receduc =
                                           forcats::fct_recode(receduc,
                                                               `Don’t know/Refused` = "DK/Ref"))
table(dec13_excerpt$receduc)
dec13_excerpt <- keyboardize_punctuation(dec13_excerpt)
table(dec13_excerpt$receduc)

pewresearch/pewmethods documentation built on March 27, 2020, 7:22 p.m.