Skip to contents

Replacing special characters one-for-one and notifies the user of replaced characters.

Usage

.fix_forbidden_tabnames(tabnames, quiet = FALSE)

Arguments

tabnames

vector of tab/sheet names

quiet

TRUE or FALSE to suppress notices of forbidden-char replacement

Value

the input vector with forbidden characters replaced/removed

Note

NA always returned as NA NULL acts like c(), i.e c(NULL, NULL)

Examples

c("' '?HisTory,*?*!@#$%^&*()_+ '[{1'}]'[:/\\]''", "", NA, NULL) |>  xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `\`
#> → Replacing forbidden character with:  `-`
#> ! Sheet names should not contain:  `/`
#> → Replacing forbidden character with:  `-`
#> ! Sheet names should not contain:  `:`
#> → Replacing forbidden character with:  `-`
#> ! Sheet names should not contain:  `*`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `?`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `?`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `[`
#> → Replacing forbidden character with:  `(`
#> ! Sheet names should not contain:  `]`
#> → Replacing forbidden character with:  `)`
#> ! Sheet names should not contain:  `a single quote ' at the start of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> ! Sheet names should not contain:  `a single quote ' at the end of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> ! Sheet names should not contain:  `the word 'history'`
#> → Replacing forbidden character with:  `hist`
#> [1] "` '#HisT,###!@#$%^##()_+ '({1'})'(---)`"
#> [2] ""                                       
#> [3] NA                                       
" ''''''" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `a single quote ' at the end of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> [1] " `"
"'''1' '" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `a single quote ' at the start of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> ! Sheet names should not contain:  `a single quote ' at the end of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> [1] "`1' `"
"'[ ]hi];'" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `[`
#> → Replacing forbidden character with:  `(`
#> ! Sheet names should not contain:  `]`
#> → Replacing forbidden character with:  `)`
#> ! Sheet names should not contain:  `a single quote ' at the start of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> ! Sheet names should not contain:  `a single quote ' at the end of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> [1] "`( )hi);`"
"!@#$%^&*()_+ {HI} ^" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `*`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `?`
#> → Replacing forbidden character with:  `#`
#> [1] "!@#$%^##()_+ {HI} ^"
"'histor'y'" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `a single quote ' at the start of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> ! Sheet names should not contain:  `a single quote ' at the end of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> [1] "`histor'y`"
"[:/] " |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `/`
#> → Replacing forbidden character with:  `-`
#> ! Sheet names should not contain:  `:`
#> → Replacing forbidden character with:  `-`
#> ! Sheet names should not contain:  `[`
#> → Replacing forbidden character with:  `(`
#> ! Sheet names should not contain:  `]`
#> → Replacing forbidden character with:  `)`
#> [1] "(--) "
"?/a\\" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `\`
#> → Replacing forbidden character with:  `-`
#> ! Sheet names should not contain:  `/`
#> → Replacing forbidden character with:  `-`
#> ! Sheet names should not contain:  `?`
#> → Replacing forbidden character with:  `#`
#> [1] "#-a-"
"?,*?*?'" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `*`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `?`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `a single quote ' at the end of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> [1] "#,####`"
"[history coursework]" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `[`
#> → Replacing forbidden character with:  `(`
#> ! Sheet names should not contain:  `]`
#> → Replacing forbidden character with:  `)`
#> ! Sheet names should not contain:  `the word 'history'`
#> → Replacing forbidden character with:  `hist`
#> [1] "(hist coursework)"
"'HISTORIC' History '''" |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `a single quote ' at the start of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> ! Sheet names should not contain:  `a single quote ' at the end of a tabname`
#> → Replacing forbidden character with:  `an empty string`
#> ! Sheet names should not contain:  `the word 'history'`
#> → Replacing forbidden character with:  `hist`
#> [1] "`HISTORIC' Hist `"
"*[history' buff]*' " |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `*`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `[`
#> → Replacing forbidden character with:  `(`
#> ! Sheet names should not contain:  `]`
#> → Replacing forbidden character with:  `)`
#> ! Sheet names should not contain:  `the word 'history'`
#> → Replacing forbidden character with:  `hist`
#> [1] "#(hist' buff)#' "
NA |> xlr:::.fix_forbidden_tabnames()
#> [1] NA
NULL |> xlr:::.fix_forbidden_tabnames()
#> character(0)
c(NULL, NA, '[hi?]') |> xlr:::.fix_forbidden_tabnames()
#> ! Sheet names should not contain:  `?`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `[`
#> → Replacing forbidden character with:  `(`
#> ! Sheet names should not contain:  `]`
#> → Replacing forbidden character with:  `)`
#> [1] NA      "(hi#)"
c(NULL, NULL) |> xlr:::.fix_forbidden_tabnames()
#> character(0)
enlist(NULL, NA, '[hi?]') |>  purrr::map(xlr:::.fix_forbidden_tabnames)
#> ! Sheet names should not contain:  `?`
#> → Replacing forbidden character with:  `#`
#> ! Sheet names should not contain:  `[`
#> → Replacing forbidden character with:  `(`
#> ! Sheet names should not contain:  `]`
#> → Replacing forbidden character with:  `)`
#> $`NULL`
#> character(0)
#> 
#> $`NA`
#> [1] NA
#> 
#> $`[hi?]`
#> [1] "(hi#)"
#>