norm_trailing_slash: Handle trailing (and optionally, leading) slashes

View source: R/norm_trailing_slash.R

norm_trailing_slashR Documentation

Handle trailing (and optionally, leading) slashes

Description

Remove, or remove and insert a single trailing forward or back slash

Usage

norm_trailing_slash(
  x,
  how = c("remove", "replace"),
  replace_with = c("forward", "back"),
  strip_leading = FALSE,
  view_res = FALSE
)

Arguments

x

A character vector

how

What kind of normalization should be performed? One of remove,replace. Defaults to remove

replace_with

If how = replace, should we replace with a forward or backslash? One of forward,back. Defaults to forward

strip_leading

Also strip the first leading slash, if present? Defaults to FALSE

view_res

Output the structure the first six rows of the input and output? Defaults to FALSE

Details

Normalization is defined as taking the input and stripping a single trailing slash, if one is present. This is performed whether removing only, or replacing; hence, this function will remove a single trailing slash and stop, or also append a single trailing slash (and if so, the type of slash as specified by replace_with).There is nothing fancy about this function; it is a useful helper for e.g. creating directory strings

Value

A character vector of length x

Note

If view_res = TRUE, the first six rows of the input and output are printed to the console via dput() (with default args). This may be useful to verify that the literal output, sans escapes, are as expected by e.g. calling View() on the deparsed output.

Examples

norm_trailing_slash(x = c("/dir1\\", "/dir1/"), how = "remove", view_res = TRUE)
norm_trailing_slash(x = c("/dir1\\", "/dir1/"), how = "replace",
  replace_with = "forward", view_res = TRUE)

slin30/wzMisc documentation built on Jan. 27, 2023, 1 a.m.