
Last chance! 50% off unlimited learning
Sale ends in
In reproducible research, not only do packages and R version have to be consistent, but also specific versions of version controlled scripts. This function allows a simple way to create an exactly copy locally of a git repository. It can use ssh keys (including GitHub deploy keys) or GitHub Personal Access Tokens.
checkoutVersion(repo, localRepoPath = ".", cred = "", ...)
Repository address in the format username/repo[/subdir][@ref|#pull]
.
Alternatively, you can specify subdir and/or ref using the respective parameters (see below);
if both is specified, the values in repo take precedence.
Character string. The path into which the git repo should be cloned, fetched, and checked out from.
Character string. Either the name of the environment variable that contains the GitHub PAT or filename of the GitHub private key file.
Additional arguments passed to git2r
functions.
Invisibly returns a git_repository class object, defined in git2r.
# NOT RUN {
tmpDir <- tempfile("")
dir.create(tmpDir)
repo <- "PredictiveEcology/reproducible"
## get latest from master branch
localRepo <- checkoutVersion("PredictiveEcology/reproducible",
localRepoPath = tmpDir)
git2r::summary(localRepo)
unlink(tmpDir, recursive = TRUE)
## get latest from development branch
localRepo <- checkoutVersion(paste0(repo, "@", "development"), localRepoPath = tmpDir)
git2r::summary(localRepo)
unlink(tmpDir, recursive = TRUE)
## get a particular commit by sha
sha <- "8179e1910e7c617fdeacad0f9d81323e6aad57c3"
localRepo <- checkoutVersion(paste0(repo, "@", sha), localRepoPath = tmpDir)
git2r::summary(localRepo)
unlink(tmpDir, recursive = TRUE)
rm(localRepo, repo)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab