Debian Codegraph @

man/copy.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/copy.R
3 \name{copy}
4 \alias{copy}
5 \alias{file_copy}
6 \alias{dir_copy}
7 \alias{link_copy}
8 \title{Copy files, directories or links}
9 \usage{
10 file_copy(path, new_path, overwrite = FALSE)
11
12 dir_copy(path, new_path, overwrite = FALSE)
13
14 link_copy(path, new_path, overwrite = FALSE)
15 }
16 \arguments{
17 \item{path}{A character vector of one or more paths.}
18
19 \item{new_path}{A character vector of paths to the new locations.}
20
21 \item{overwrite}{Overwrite files if they exist. If this is \code{FALSE} and the
22 file exists an error will be thrown.}
23 }
24 \value{
25 The new path (invisibly).
26 }
27 \description{
28 \code{file_copy()} copies files.
29
30 \code{link_copy()} creates a new link pointing to the same location as the previous link.
31
32 \code{dir_copy()} copies the directory recursively at the new location.
33 }
34 \details{
35 The behavior of \code{dir_copy()} differs slightly than that of \code{file.copy()} when
36 \code{overwrite = TRUE}. The directory will always be copied to \code{new_path}, even
37 if the name differs from the basename of \code{path}.
38 }
39 \examples{
40 \dontshow{.old_wd <- setwd(tempdir())}
41 file_create("foo")
42 file_copy("foo", "bar")
43 try(file_copy("foo", "bar"))
44 file_copy("foo", "bar", overwrite = TRUE)
45 file_delete(c("foo", "bar"))
46
47 dir_create("foo")
48 # Create a directory and put a few files in it
49 files <- file_create(c("foo/bar", "foo/baz"))
50 file_exists(files)
51
52 # Copy the directory
53 dir_copy("foo", "foo2")
54 file_exists(path("foo2", path_file(files)))
55
56 # Create a link to the directory
57 link_create(path_abs("foo"), "loo")
58 link_path("loo")
59 link_copy("loo", "loo2")
60 link_path("loo2")
61
62 # Cleanup
63 dir_delete(c("foo", "foo2"))
64 link_delete(c("loo", "loo2"))
65 \dontshow{setwd(.old_wd)}
66 }