pgrid_help: 'expand.grid' for 'paste' and 'paste0'

View source: R/pgrid.R

pgrid_helpR Documentation

expand.grid for paste and paste0

Description

Generate all combinations of the values of 2 or more vectors and glue the combinations into a single character vector.

Usage

pgrid_help()

pgrid(.p, ..., .ch = F, .crossed = F, .na = F)

pgrid0(..., .ch = F, .crossed = F, .na = FALSE)

pgrid1(..., .ch = F, .crossed = F, .na = FALSE)

pgridN(.p, ..., .ch = F, .na = FALSE)

pgridX(.p, ..., .ch = F, .na = FALSE)

Arguments

.p

A complete character scalar to use as the 'paste'.

...

Non-empty atomic objects.

.ch, .na

Non-NA logical scalars indicating, respectively, whether to split each ... arguments into its constituent characters after conversion to mode 'character' and whether NA values in ... arguments are valid.

.crossed

TRUE or FALSE indicating whether to construct the result to look like a fully-crossed model. See the .crossed argument section for details.

Value

A character vector.

Functions

  • pgrid(): Converts the N ... arguments to character (with additional optional pre-processing) and create a character vector with each element consisting of sub-strings from across ... arguments pasted together using the 'paste' .p. See the the .crossed argument section for how the value of .crossed affects the return value.

  • pgrid0(): Calls pgrid with .p = "" (blank).

  • pgrid1(): Calls pgrid with .p = " " (space).

  • pgridN(): Calls pgrid with .crossed = FALSE (see the .crossed argument).

  • pgridX(): Calls pgrid with .crossed = TRUE (see the .crossed argument).

The .crossed Argument

The following console excerpt shows the effect of the value of .crossed:

> x <- c("A", "B", "C")
> y <- c(1, 2)
> z <- c("a", "b")
> p <- "."
> list(n = sort(pgrid(p, x, y, z, .crossed = FALSE)),
       y = sort(pgrid(p, x, y, z, .crossed = TRUE )))
$n
[1] "A.1.a" "A.1.b" "A.2.a" "A.2.b" "B.1.a" "B.1.b"
[7] "B.2.a" "B.2.b" "C.1.a" "C.1.b" "C.2.a" "C.2.b"

$y
 [1] "1"     "1.a"   "1.b"   "2"     "2.a"   "2.b"
 [7] "a"     "A"     "A.1"   "A.1.a" "A.1.b" "A.2"
[13] "A.2.a" "A.2.b" "A.a"   "A.b"   "b"     "B"
[19] "B.1"   "B.1.a" "B.1.b" "B.2"   "B.2.a" "B.2.b"
[25] "B.a"   "B.b"   "C"     "C.1"   "C.1.a" "C.1.b"
[31] "C.2"   "C.2.a" "C.2.b" "C.a"   "C.b"

See Also

Other strings: blank(), chn(), delim(), fsub(), gr, ipat(), makestr(), markdown_help(), maxnch(), ox(), ox_vals(), revstr(), spaces(), ss_help(), tocase(), weave()

Examples

x <- c("A", "B", "C")
y <- c(1, 2)
z <- c("a", "b")
pgrid(".", x, y, z, .crossed = F)
pgrid(".", x, y, z, .crossed = T)
pgridN(".", x, y, y)
pgridX(".", x, y, z)
pgrid0(x, y, z)
pgrid1(x, y, z)

j-martineau/uj documentation built on Sept. 14, 2024, 4:40 a.m.