Learn R Programming

fritools (version 3.3.0)

file_copy: Force Copying a File While backing it up

Description

file.copy has an argument overwrite that allows for overwriting existing files. But I often want to overwrite an existing file while creating a backup copy of that file.

Usage

file_copy(from, to, stop_on_error = FALSE, ...)

Arguments

from
to
stop_on_error

Throw an exception on error?

...

Arguments passed to file.copy.

Value

TRUE on success, FALSE otherwise.

See Also

Other file utilities: file_modified_last(), file_save(), find_files(), get_mtime(), get_unique_string(), is_files_current(), is_path(), paths, search_files(), split_code_file(), touch()

Other operating system functions: file_save(), get_boolean_envvar(), get_run_r_tests(), is_installed(), is_r_package_installed(), is_success(), is_windows(), view(), vim(), with_dir()

Examples

Run this code
# NOT RUN {
touch(f1 <- file.path(tempdir(), "first.R"))
touch(f2 <- file.path(tempdir(), "second.R"))
file_copy(f2, f1)
list.files(tempdir(), pattern = "first.*\\.R")
dir <- file.path(tempdir(), "subdir")
dir.create(dir)
file_copy(f1, dir)
touch(f1)
file_copy(f1, dir)
list.files(dir, pattern = "first.*\\.R")
# }

Run the code above in your browser using DataLab