From ee28b4aab283bb009fe723f7fae2fabded0a03e5 Mon Sep 17 00:00:00 2001 From: Noam Ross Date: Tue, 14 Nov 2023 14:40:21 -0500 Subject: [PATCH] Set overwrite param for example_repo and use withr --- R/example_repo.R | 10 +++++----- man/create_example_repo.Rd | 5 ++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/R/example_repo.R b/R/example_repo.R index ee7af64..3d0c513 100644 --- a/R/example_repo.R +++ b/R/example_repo.R @@ -6,14 +6,14 @@ #' @param reporter the reporter to use when building targets with [targets::tar_make()]. Defaults to "silent". #' @param s3 Whether the repository should use S3 storage for targets. Note that #' the S3 endpoint and bucket must already be available. +#' @param overwrite Whether to overwrite the directory if it already exists. #' @return The path to the created repository #' @export -create_example_repo <- function(dir = fs::file_temp("relic_example_"), reporter = "silent", s3 = TRUE) { - check_installed(c("targets", "glue")) - if (dir_exists(dir)) dir_delete(dir) +create_example_repo <- function(dir = fs::file_temp("relic_example_"), reporter = "silent", s3 = TRUE, overwrite = TRUE) { + check_installed(c("targets", "glue", "withr")) + if (dir_exists(dir)) if (overwrite) dir_delete(dir) else abort("Directory already exists") dir_create(dir) - od <- setwd(dir) - on.exit(setwd(od)) + withr::local_dir(dir) repo <- git2r::init() # Configure the repository to use a generic user name and email address git2r::config(repo, user.name = "relic-bot", user.email = "relic@relic.r.pacakge") diff --git a/man/create_example_repo.Rd b/man/create_example_repo.Rd index 27265c5..9dd78d2 100644 --- a/man/create_example_repo.Rd +++ b/man/create_example_repo.Rd @@ -7,7 +7,8 @@ create_example_repo( dir = fs::file_temp("relic_example_"), reporter = "silent", - s3 = TRUE + s3 = TRUE, + overwrite = TRUE ) } \arguments{ @@ -17,6 +18,8 @@ create_example_repo( \item{s3}{Whether the repository should use S3 storage for targets. Note that the S3 endpoint and bucket must already be available.} + +\item{overwrite}{Whether to overwrite the directory if it already exists.} } \value{ The path to the created repository