cString: cString: Create a c() Expression From Character Vector

Description Usage Arguments Details Value Side effects Author(s) Examples

View source: R/cString.R

Description

Convert a character vector to comma-separated list of quoted strings

Usage

1
2
3
4
5
6
7
8
9
cString(
  char.vector,
  wrap = TRUE,
  var.name = "",
  prefix = " <- c(",
  indent = 3,
  suffix = ")",
  sep = "\", \""
)

Arguments

char.vector

a character vector containing one or more elements

wrap

logical or numeric value indicating whether the string should be wrapped at a given width. If TRUE, wrap at 0.9*getOption("width"); if FALSE do not wrap; if numeric, wrap at that number of characters. The output will be broken after the comma separators.

var.name

character string to be prepended to the output; typically the name of a variable to which the output will be assigned.

prefix

character string that will be inserted between the var.name and the commas-separated quoted list; default is ' <- c('.

indent

integer indicating number of spaces by which to indent all lines except the first; default is 3.

suffix

character string to append after the commas-separated list; default is ')'. If prefix is set to "" (empty string), suffix will automatically be set to that as well.

sep

character string indicating the separator between elements; defaults to '", "' (don't forget the double quotes)

Details

This is a handy function for creating a c("element1", "element2", "etc") expression from a character vector that can them be pasted into your code. Note that it returns a single element character vector not an expression object.

Value

a character value containing the input strings as a comma-separated quoted list, returned invisibly.

Side effects

The output string is printed to standard out using cat()

Author(s)

M.W.Rowe, mwr.stats@gmail.com

Examples

1
2
3
 animals <- c("dog", "cat", "moose", "antelope", "aardvark", "goose", "rat",
  "elephant", "turkey", "cow", "platypus", "human", "crocodile", "rooster")
 cString(animals, wrap=80, var.name="zoo")

mwrowe/microRutils documentation built on June 12, 2021, 2:41 p.m.