Similar to https://stackoverflow.com/a/10268255/, I would like a function that automatically makes sub-directories where they don't exist, when file.copy
is used. Current I am getting the error:
In file.copy( ... :
'recursive' will be ignored as 'to' is not a single existing directory
Unfortunately using a function like:
my.file.copy<- function(from, to, ...) {
todir <- dirname(to)
if (!isTRUE(file.info(todir)$isdir)) dir.create(todir, recursive=TRUE)
file.copy(from = from, to = to, ...)
}
does not work as dirname
strips the last subdirectory if to
is a directory.