Description Usage Arguments Value Examples
Convert Long File Paths to Simple Paths
1 | to_simple_names(paths, method = 1L, get_base = NULL, sha1_digits = 4)
|
paths |
vector of character containing file paths |
method |
|
get_base |
function taking a vector of character as input and returning
a vector of character as output. If not |
sha1_digits |
number of digits used when |
vector of character as long as paths
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | paths <- c("v1_ugly_name_1.doc", "v1_very_ugly_name.xml",
"v2_ugly_name_1.docx", "v2_very_ugly_name.xmlx")
to_simple_names(paths, method = 1L)
writeLines(sort(to_simple_names(paths, method = 2L)))
# All sha1 are different because all base names (file name without extension
# by default) are different. If you want to give the same sha1 to files that
# correspond to each other but have a different extension, set the function
# that extracts the "base name" of the file:
get_base <- function(x) kwb.utils::removeExtension(gsub("^v\\d+_", "", x))
writeLines(sort(to_simple_names(paths, method = 2L, get_base = get_base)))
# Now the file names that have the same base name (neglecting the prefix
# v1_ or v2_) get the same sha1 and thus appear as groups in the sorted
# file list
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.