Learn R Programming

corpora (version 0.6)

qw: Split string into words, similar to qw() in Perl (corpora)

Description

This function splits one or more character strings into words. By default, the strings are split on whitespace in order to emulate Perl's qw() (quote words) functionality.

Usage

qw(s, sep="\\s+", names=FALSE)

Value

A character vector of the resulting words. Multiple strings in s are flattened into a single vector.

If names=TRUE, the words are used both as values and as labels of the character vectors, which is convenient when iterating over it with lapply or sapply.

Arguments

s

one or more strings to be split (a character vector)

sep

PCRE regular expression on which to split (defaults to whitespace)

names

if TRUE, the resulting character vector is labelled with itself, which is convenient for lapply and similar functions

Author

Stephanie Evert (https://purl.org/stephanie.evert)

Examples

Run this code
qw(c("alpha beta gamma", "42 111" ))
qw("alpha beta gamma", names=TRUE)
qw("words with blanks,  sep by commas", sep="\\s*,\\s*")

Run the code above in your browser using DataLab