vector2string: Coverts values from a vector to a concatenation of substrings...

View source: R/vector2string.R

vector2stringR Documentation

Coverts values from a vector to a concatenation of substrings separated by user-specified string separator.

Description

LIMITATION: The function interprets all substrings in the vector either as of type 'int' or 'char'. A function that interprets the type of each substring dynamically may one day be written by an R-guru.

Usage

vector2string(
  vector = c(" 12345", "4X3200", "1X2890"),
  SS = "', '",
  type = "char"
)

Arguments

vector

integer or character vector

SS

User-specified string separator. (default value: SS = "', '").

type

Tell function the class of the vector.

Details

Franc Brglez, Wed Dec 9 15:43:59 EST 2009

Examples

library(stringi, quietly = TRUE)
## Here we convert a binary vector to a binary string representing an integer:
binV <- c(1, 0, 0, 1)
strS <- vector2string(binV, type = "int")
## Here we convert a binary vector to string representing a binary sequence:
binV <- c(1,0,0,1)
seqS <- vector2string(binV, SS=" ", type="char")
## Here we convert a vector of substrings to colon-separated string:
subsV <- c("I", "am", "done")
strS <- vector2string(subsV, SS = ":", type = "char")

## Making an SQL IS IN statement
ids <- c(" 12345", "4X3200", "1X2890")
stri_c("and master.id in ('", vector2string(ids, "', '"), "') ")

rmsharp/rmsutilityr documentation built on Feb. 13, 2024, 6:01 p.m.