Given the following code:
file.copy("foo", "bar") # TRUE
A file "bar" is created, but it is not formed as a copy of the directory "foo"; rather, it seems to just be an empty file. This can be verified with e.g.
> file.info("bar")[, 1:3]
size isdir mode
bar 0 FALSE 755
It would be useful if R's 'file.copy()' followed the shell semantics here, whereby a call to 'file.copy(<dir>, ...)' acted similarly to 'cp -R <dir> ...'.
Alternatively, a separate API 'dir.copy()' could be useful here.
An older mailing list post seems to suggest that file.copy() was intended to do this (at least in some development version of R) but perhaps that change was rolled back? http://r.789695.n4.nabble.com/copy-directory-command-td881914.html
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.1
The r-help post was probably referring to the recursive argument, which seems to work as long as the destination directory (to contain "foo") exists. This is different from the "cp -R" behavior. I guess it wouldn't be hard to perform the recursive copy into the parent directory, and then rename it. But that would break if the "to" directory was the same as the parent of "from". Right now, file.copy("foo", ".", recursive=TRUE) seems to just copy "foo" over itself without any complaint, even though it does attempt to catch that case. A general solution would recursively copy the _contents_ of "foo" into a new directory. That wouldn't be too hard to implement at the R level. Please consider submitting a patch.