Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# usethis (development version)

* `use_article()` now creates the file in the `vignettes/articles/` (#548).

* `use_lifecycle()` has been updated for changes in our lifecycle workflow
(#1323).

Expand Down
14 changes: 11 additions & 3 deletions R/vignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,29 @@ use_vignette <- function(name, title = name) {
use_article <- function(name, title = name) {
check_is_package("use_article()")

use_vignette_template("article.Rmd", name, title)
use_vignette_template("article.Rmd", name, title, subdir = "articles")
use_build_ignore("vignettes/articles")

invisible()
}

use_vignette_template <- function(template, name, title) {
use_vignette_template <- function(template, name, title, subdir = NULL) {
stopifnot(is_string(name))
stopifnot(is_string(title))

use_directory("vignettes")
if (!is.null(subdir)) {
use_directory(path("vignettes", subdir))
}
use_git_ignore(c("*.html", "*.R"), directory = "vignettes")
use_dependency("rmarkdown", "Suggests")

path <- path("vignettes", asciify(name), ext = "Rmd")
if (!is.null(subdir)) {
path <- path("vignettes", subdir, asciify(name), ext = "Rmd")
} else {
path <- path("vignettes", asciify(name), ext = "Rmd")
}


data <- list(
Package = project_name(),
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-vignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ test_that("use_vignette() does the promised setup", {
c(VignetteBuilder = "knitr")
)
})

test_that("use_article goes in article subdirectory", {
create_local_package()

use_article("test")
expect_proj_file("vignettes/articles/test.Rmd")
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comes up so much we have a helper for it:

https://github.com/r-lib/usethis/blob/master/tests/testthat/helper.R#L131