hpaste

0th

Percentile

Pasting a vector into a human-readable string

Pasting a vector into a human-readable string such as "1, 2, 3, ..., 10".

Keywords
programming
Usage
## S3 method for class 'default':
hpaste(x, collapse=", ", lastCollapse=NULL, maxHead=if (missing(lastCollapse)) 3 else Inf, maxTail=if (is.finite(maxHead)) 1 else Inf, abbreviate="...", quote=NULL, ...)
Arguments
x
A vector whose elements should be pasted together.
collapse, lastCollapse
The character strings to collapse the elements together, where lastCollapse is specifying the collapse string used between the last two elements. If lastCollapse
maxHead, maxTail, abbreviate
Non-negative integers (also Inf) specifying the maxium number of elements of the beginning and then end of the vector to be outputted
quote
An character string used to quote each element.
...
Not used.
Value

See Also

paste().

Aliases
  • hpaste.default
  • hpaste
Examples
# Some vectors
x <- 1:6
y <- 1:10
z <- LETTERS[x]

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Abbreviation of output vector
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf("x = %s.
", hpaste(x))
## x = 1, 2, 3, ..., 6.

printf("x = %s.
", hpaste(x, maxHead=2))
## x = 1, 2, ..., 6.

printf("x = %s.
", hpaste(x), maxHead=3) # Default
## x = 1, 2, 3, ..., 6.

# It will never output 1, 2, 3, 4, ..., 6
printf("x = %s.
", hpaste(x, maxHead=4))
## x = 1, 2, 3, 4, 5 and 6.

# Showing the tail
printf("x = %s.
", hpaste(x, maxHead=1, maxTail=2))
## x = 1, ..., 5, 6.

# Turning off abbreviation
printf("y = %s.
", hpaste(y, maxHead=Inf))
## y = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

## ...or simply
printf("y = %s.
", paste(y, collapse=", "))
## y = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Adding a special separator before the last element
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Change last separator
printf("x = %s.
", hpaste(x, lastCollapse="and "))
## x = 1, 2, 3, 4, 5 and 6.


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Qouting
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
printf("z = %s.
", hpaste(z, quote="'"))
## z = 'A', 'B', 'C', ..., 'F'.

printf("z = %s.
", hpaste(z, quote="'", maxHead=Inf))
## z = 'A', 'B', 'C', 'D', 'E', 'F'.
Documentation reproduced from package R.utils, version 1.7.3, License: LGPL (>= 2.1)

Community examples

Looks like there are no examples yet.