prefix: Add leading characters to a string

Description Usage Arguments Value Examples

View source: R/prefix.r

Description

Add leading characters to a string. This function is useful for ensuring, say, files get sorted in a particular order. For example, on some operating systems a file name "file 1" would come first, then "file 10", then "file 11", "file 12", etc., then "file 2", "file 21", amd sp pn. Using prefix you can add ne or more leading zeros so that file names are as "file 01", "file 02", "file 03", and so on... and they will sort that way.

Usage

1
prefix(x, len, pad = "0")

Arguments

x

Character or character list to which to add a prefix.

len

The total number of characters desired for each string. If a string is already this length or longer then nothing will be prefixed to that string.

pad

Character. Symbol to prefix to each string.

Value

Character or character vector.

Examples

1
2
3
prefix(1:5, len=2)
prefix(1:5, len=5)
prefix(1:5, len=3, pad='!')

adamlilith/omnibus documentation built on Nov. 21, 2018, 11:01 a.m.