Calls file.copy
under the hood but gives a message about the indices
and paths of the files that could not be copied.
copy_files_to_target_dir(from_paths, target_dir, target_files)
from_paths | paths to the files to be copied |
---|---|
target_dir | path to the target directory |
target_files | relative paths to the target files, relative to
|
root <- system.file(package = "kwb.file") relative_paths <- dir(root, recursive = TRUE) # The original files are in root or in different subfolders relative_paths#> [1] "DESCRIPTION" "extdata/setup_package.R" #> [3] "help/aliases.rds" "help/AnIndex" #> [5] "help/kwb.file.rdb" "help/kwb.file.rdx" #> [7] "help/paths.rds" "html/00Index.html" #> [9] "html/R.css" "INDEX" #> [11] "LICENSE" "Meta/features.rds" #> [13] "Meta/hsearch.rds" "Meta/links.rds" #> [15] "Meta/nsInfo.rds" "Meta/package.rds" #> [17] "Meta/Rd.rds" "NAMESPACE" #> [19] "NEWS.md" "R/kwb.file" #> [21] "R/kwb.file.rdb" "R/kwb.file.rdx"# Create a temporary target folder target_dir <- kwb.utils::createDirectory(file.path(tempdir(), "target"))#> The directory "/tmp/Rtmpf1mGZa/target" was created.# Copy all files into one target folder without subfolders from_paths <- file.path(root, relative_paths) to_paths <- basename(from_paths) # Make sure that the target file names contain no duplicates, otherwise # an error is raised to_paths <- kwb.utils::makeUnique(to_paths, warn = FALSE) # Copy the files copy_files_to_target_dir(from_paths, target_dir, to_paths) # Look at the result dir(target_dir, recursive = TRUE)#> [1] "00Index.html" "aliases.rds" "AnIndex" "DESCRIPTION" #> [5] "features.rds" "hsearch.rds" "INDEX" "kwb.file" #> [9] "kwb.file.rdb" "kwb.file.rdb.1" "kwb.file.rdx" "kwb.file.rdx.1" #> [13] "LICENSE" "links.rds" "NAMESPACE" "NEWS.md" #> [17] "nsInfo.rds" "package.rds" "paths.rds" "R.css" #> [21] "Rd.rds" "setup_package.R"