Easily parse a vector into a character value
vecTxt.Rd
vecTxtQ
, vecTxtB
, and vecTxtM
and are convenience functions
with default quotes that can be useful when working in R Markdown
documents.
Usage
vecTxt(
vector,
delimiter = ", ",
useQuote = "",
firstDelimiter = NULL,
lastDelimiter = " & ",
firstElements = 0,
lastElements = 1,
lastHasPrecedence = TRUE
)
vecTxtQ(vector, useQuote = "'", ...)
vecTxtB(vector, useQuote = "`", ...)
vecTxtM(vector, useQuote = "$", ...)
Arguments
- vector
The vector to process.
- delimiter, firstDelimiter, lastDelimiter
The delimiters to use for respectively the middle, first
firstElements
, and lastlastElements
elements.- useQuote
This character string is pre- and appended to all elements; so use this to quote all elements (
useQuote="'"
), doublequote all elements (useQuote='"'
), or anything else (e.g.useQuote='|'
). The only difference betweenvecTxt
andvecTxtQ
is that the latter by default quotes the elements.- firstElements, lastElements
The number of elements for which to use the first respective last delimiters
- lastHasPrecedence
If the vector is very short, it's possible that the sum of firstElements and lastElements is larger than the vector length. In that case, downwardly adjust the number of elements to separate with the first delimiter (
TRUE
) or the number of elements to separate with the last delimiter (FALSE
)?- ...
Any addition arguments to
vecTxtQ
are passed on tovecTxt
.
Examples
vecTxtQ(names(mtcars));
#> [1] "'mpg', 'cyl', 'disp', 'hp', 'drat', 'wt', 'qsec', 'vs', 'am', 'gear' & 'carb'"