Skip to content

Instantly share code, notes, and snippets.

@kevinrue
Last active July 3, 2019 18:58
Show Gist options
  • Save kevinrue/6ecbc6d5070fb9346fd48dcbbb1d93ee to your computer and use it in GitHub Desktop.
Save kevinrue/6ecbc6d5070fb9346fd48dcbbb1d93ee to your computer and use it in GitHub Desktop.
A function to clone the content of an R package (perhaps other repositories too)
cloneRepo <- function(from, to) {
repoFiles <- list.files(cloneSourceFolder, all.files = TRUE, include.dirs = TRUE)
repoFiles <- setdiff(repoFiles, c(".", "..", ".git"))
dir.create(to, recursive = TRUE)
for (rootFile in repoFiles) {
message(rootFile)
file.copy(
from = file.path(from, rootFile),
to = file.path(to),
recursive = TRUE, overwrite = TRUE)
}
}
# example
cloneSourceFolder <- "/Users/username/git/package"
cloneDestinationFolder <- "/Users/username/git/package_clone"
# usage
cloneRepo(cloneSourceFolder, cloneDestinationFolder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment