Make Sure that Strings End With Slash
Arguments
- x
vector of character
- method
integer value specifying the implementation method.
1
(default): Find strings without ending slash and append slash to these strings.2
: Remove one or more slashes at the end and append slash to all strings.3
: Append slash to all strings and replace multiple occurrences of slash at the end with one slash. Method 1 is the fastest but does not replace multiple trailing slashes with only one trailing slash (see examples).
Examples
assertFinalSlash(c("a", "b", "c"))
#> [1] "a/" "b/" "c/"
assertFinalSlash(c("a/", "b/", "c/"))
#> [1] "a/" "b/" "c/"
assertFinalSlash(c("a//", "b", "c/"))
#> [1] "a//" "b/" "c/"
# Use method 2 or 3 to replace multiple slashes with one slash
assertFinalSlash(c("a//", "b", "c/"), method = 2)
#> [1] "a/" "b/" "c/"
assertFinalSlash(c("a//", "b", "c/"), method = 3)
#> [1] "a/" "b/" "c/"