convertVector2sentence: Function that converts a vector to an English language list:...

Description Usage Arguments Value History/development log Author(s) See Also Examples

View source: R/convertVector2sentence.R

Description

Function that converts a vector to an English language list: e.g. 1:3 becomes 1, 2 and 3

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
convertVector2sentence(
  x,
  andChar = " and ",
  quoted = FALSE,
  quoteChar = "\"",
  italicY = FALSE
)

convertVectorToSentence(
  x,
  andChar = " and ",
  quoted = FALSE,
  quoteChar = "\"",
  italicY = FALSE
)

Arguments

x

input vector or one dimensional list to convert

andChar

string to put between penultimate and last entry

quoted

logical indicating whether each item should be quoted and hence

quoteChar

string to put around each item to quote it

italicY

logical to have items italicised

Value

string

History/development log

Started before 5.iv.21 10.iv.21: added synonym convertVectorToSentence

Author(s)

Chris Evans

See Also

hyphenateWords for another utility function to convert numbers to English words, e.g. "87" to "eighty-seven".

Other text utilities: hyphenateWords()

Other converting utilities: convert2CEdate()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
### default behaviour
convertVector2sentence(1:4)
### [1] "1, 2, 3 and 4"

### default behaviour
convertVector2sentence(1:4, quoted = TRUE)
### [1] "\"1\", \"2\", \"3\" and \"4\""

### change andChar (note the spaces,
###  I can't see why you wouldn't want them but ...)
convertVector2sentence(1:4, andChar = ' & ')
### [1] "1, 2, 3 & 4"

### change the quoting character (note no spaces)
convertVector2sentence(1:4, quoted = TRUE, quoteChar = "'")
### [1] "'1', '2', '3' and '4'"

convertVector2sentence(1:4, italicY = TRUE) # italicises the items
### and now italics and quotation:
convertVector2sentence(1:4, italicY = TRUE, quoted = TRUE)

cpsyctc/CECPfuns documentation built on Dec. 26, 2021, 1:19 p.m.