sfill {dreamerr}R Documentation

Fills a string vector with a symbol

Description

Fills a string vector with a user-provided symbol, up to the required length.

Usage

sfill(x = "", n = NULL, symbol = " ", right = FALSE, anchor, na = "NA")

Arguments

x

A character vector.

n

A positive integer giving the total expected length of each character string. Can be NULL (default). If NULL, then n is set to the maximum number of characters in x (i.e. max(nchar(x))).

symbol

Character scalar, default to " ". The symbol used to fill.

right

Logical, default is FALSE. Whether the character vector should be filled on the left( default) or on the right.

anchor

Character scalar, can be missing. If provided, the filling is done up to this anchor. See examples.

na

Character that will replace any NA value in input. Default is "NA".

Value

Returns a character vector of the same length as x.

Examples


# Some self-explaining examples
x = c("hello", "I", "am", "No-one")
cat(sep = "\n", sfill(x))
cat(sep = "\n", sfill(x, symbol = "."))
cat(sep = "\n", sfill(x, symbol = ".", n = 15))
cat(sep = "\n", sfill(x, symbol = ".", right = TRUE))

cat(sep = "\n", paste(sfill(x, symbol = ".", right = TRUE), ":", 1:4))

# Argument 'anchor' can be useful when using numeric vectors
x = c(-15.5, 1253, 32.52, 665.542)
cat(sep = "\n", sfill(x))
cat(sep = "\n", sfill(x, anchor = "."))


[Package dreamerr version 1.4.0 Index]