Skip to content

Commit

Permalink
Better use_template usage.
Browse files Browse the repository at this point in the history
Closes #76.
  • Loading branch information
jonthegeek committed Sep 16, 2024
1 parent 7513bce commit 73dbc09
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# tidytuesdayR (development version)

* [bug fix] `use_tidytemplate()` now explicitly takes an `ignore` argument, rather than passing (almost entirely overruled) `...` through to `usethis::use_template()`. (@jonthegeek, #76)

# tidytuesdayR 1.1.2

* [maintenance] tidytuesdayR now uses the {gh} package to manage all interactions with the GitHub API. This should make the package more stable and easier to maintain. (@jonthegeek, #78)
Expand Down
24 changes: 13 additions & 11 deletions R/use_tidytemplate.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#' Use the tidytemplate Rmd for starting your analysis with a leg up for
#' processing
#'
#' @param name name of your TidyTuesday analysis file
#' @param open should the file be opened after being created
#' @param ... arguments to be passed to [usethis::use_template()]
#' @param refdate date to use as reference to determine which TidyTuesday to use
#' @inheritParams usethis::use_template
#' @param name A name for your generated TidyTuesday analysis Rmd, such as
#' "My_TidyTuesday.Rmd".
#' @param refdate Date to use as reference to determine which TidyTuesday to use
#' for the template. Either date object or character string in YYYY-MM-DD
#' format.
#'
Expand All @@ -19,22 +19,24 @@
#'
#' @export
use_tidytemplate <- function(name = NULL,
open = interactive(),
...,
refdate = today()) {
stopifnot(inherits(refdate, "Date") | valid_date(refdate))
open = rlang::is_interactive(),
refdate = today(),
ignore = FALSE) {
stopifnot(valid_date(refdate))
last_tt <- last_tuesday(refdate)

if (is.null(name)) {
name <- paste0(format(last_tt, "%Y_%m_%d"), "_tidy_tuesday.Rmd")
}

usethis::use_template("tidytemplate.Rmd",
usethis::use_template(
"tidytemplate.Rmd",
save_as = name,
data = list(
call_date = today(),
call_tuesday = format(last_tt, "%Y-%m-%d")
),
package = "tidytuesdayR", ..., open = open
package = "tidytuesdayR",
ignore = ignore,
open = open
)
}
19 changes: 13 additions & 6 deletions man/use_tidytemplate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-use_tidytemplate.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test_that("use_tidytemplate processes inputs", {
call_tuesday = "2024-08-20"
),
package = "tidytuesdayR",
ignore = FALSE,
open = FALSE
)
)
Expand Down

0 comments on commit 73dbc09

Please sign in to comment.