Skip to content

Commit b1038d5

Browse files
authored
Support title in project creation (#260)
* Support title in project creation closes #148 - Behavior of `quarto_create_project()` differs from `quarto create-project` since the former "requires" the creation of a new directory * Add NEWS * title arg only works for v1.5.15+ * Bump version * missing name needs to be checked first
1 parent c1ef09a commit b1038d5

File tree

5 files changed

+98
-6
lines changed

5 files changed

+98
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: quarto
22
Title: R Interface to 'Quarto' Markdown Publishing System
3-
Version: 1.4.4.9019
3+
Version: 1.4.4.9020
44
Authors@R: c(
55
person("JJ", "Allaire", , "[email protected]", role = "aut",
66
comment = c(ORCID = "0000-0003-0174-9868")),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# quarto (development version)
22

3+
- `quarto_create_project()` gains a `title` argument to set the project title independently from the directory name. This allows creating projects with custom titles, including when using `name = "."` to create a project in the current directory (thanks, @davidkane9, #148). This matches with `--title` addition for `quarto create project` in Quarto CLI v1.5.15.
4+
35
- `quarto_render(output_file = )` now sets the `output-file` Quarto metadata instead of the `--output` CLI flag. This allows the output file information to correctly be processed by Quarto, as if passed in a YAML header. e.g. it allows to support multiple output formats in the same render call. `quarto_render(quarto_args = c('--output', 'dummy.html'))` can still be used to set the `--output` CLI flag to enforce using the CLI flag and not the metadata processed by Quarto (#251, #43).
46

57
- Added `check_newer_version()` function to check if a newer version of Quarto is available. The function compares the current Quarto version against the latest stable and prerelease versions. It is aimed for verbosity by default (`verbose = TRUE`), but `verbose = FALSE` can also be set for just checking update availability with TRUE or FALSE return values. Version information is cached per session for up to 24 hours to minimize network requests.

R/create.R

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
#'
1212
#' @param type The type of project to create. As of Quarto 1.4, it can be one of
1313
#' `r paste0("\\code{", paste(quarto_project_type, collapse = "}, \\code{"),"}")`.
14-
#' @param name The name of the project and the directory that will be created.
14+
#' @param name The name of the project and the directory that will be created. Special case
15+
#' is to use `name = "."` to create the project in the current directory. In that case provide `title`
16+
#' to set the project title.
17+
#' @param title The title of the project. By default, it will be the name of the project, same as directory name created.
18+
#' or "My project" if `name = "."`. If you want to set a different title, provide it here.
1519
#' @param dir The directory in which to create the new Quarto project, i.e. the
1620
#' parent directory.
1721
#'
@@ -23,7 +27,17 @@
2327
#'
2428
#' @examples
2529
#' \dontrun{
30+
#' # Create a new project directory in another directory
2631
#' quarto_create_project("my-first-quarto-project", dir = "~/tmp")
32+
#'
33+
#' # Create a new project directory in the current directory
34+
#' quarto_create_project("my-first-quarto-project")
35+
#'
36+
#' # Create a new project with a different title
37+
#' quarto_create_project("my-first-quarto-project", title = "My Quarto Project")
38+
#'
39+
#' # Create a new project inside the current directory directly
40+
#' quarto_create_project(".", title = "My Quarto Project")
2741
#' }
2842
#'
2943
#'
@@ -32,23 +46,41 @@ quarto_create_project <- function(
3246
name,
3347
type = "default",
3448
dir = ".",
49+
title = name,
3550
no_prompt = FALSE,
3651
quiet = FALSE,
3752
quarto_args = NULL
3853
) {
3954
check_quarto_version(
4055
"1.4",
41-
"quarto create project",
56+
"quarto create project <type> <name>",
4257
"https://quarto.org/docs/projects/quarto-projects.html"
4358
)
4459

4560
if (rlang::is_missing(name)) {
4661
cli::cli_abort("You need to provide {.arg name} for the new project.")
4762
}
4863

64+
# If title is provided, check for Quarto version 1.5.15 or higher
65+
if (title != name) {
66+
check_quarto_version(
67+
"1.5.15",
68+
"quarto create project <type> <name> <title>",
69+
"https://quarto.org/docs/projects/quarto-projects.html"
70+
)
71+
}
72+
4973
if (rlang::is_interactive() && !no_prompt) {
74+
folder_msg <- if (name != ".") {
75+
"as a folder named {.strong {name}}"
76+
}
5077
cli::cli_inform(c(
51-
"This will create a new Quarto {.emph {type}} project as a folder named {.strong {name}} in {.path {xfun::normalize_path(dir)}}."
78+
paste(
79+
"This will create a new Quarto {.emph {type}} project",
80+
folder_msg,
81+
"in {.path {xfun::normalize_path(dir)}}."
82+
),
83+
"Project title will be set to {.strong {title}}."
5284
))
5385
prompt_value <- tolower(readline(sprintf("Do you want to proceed (Y/n)? ")))
5486
if (!prompt_value %in% c("", "y")) {
@@ -62,7 +94,7 @@ quarto_create_project <- function(
6294
"project",
6395
type,
6496
name,
65-
name,
97+
title,
6698
"--no-prompt",
6799
"--no-open",
68100
if (is_quiet(quiet)) cli_arg_quiet(),

man/quarto_create_project.Rd

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-create.R

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,45 @@ test_that("create project only available for 1.4", {
3636
variant = "before-1-4"
3737
)
3838
})
39+
40+
test_that("Create a quarto project in another directory with a different title", {
41+
skip_if_no_quarto("1.5.15")
42+
tempdir <- withr::local_tempdir()
43+
curr_wd <- getwd()
44+
expect_no_error(quarto_create_project(
45+
name = "test-project",
46+
title = "Test Project",
47+
dir = tempdir,
48+
quiet = TRUE,
49+
no_prompt = TRUE
50+
))
51+
expect_true(dir.exists(file.path(tempdir, "test-project")))
52+
expect_identical(curr_wd, getwd())
53+
expect_identical(
54+
yaml::read_yaml(
55+
file.path(tempdir, "test-project", "_quarto.yml")
56+
)$project$title,
57+
"Test Project"
58+
)
59+
})
60+
61+
test_that("Create a quarto project in the same directory", {
62+
skip_if_no_quarto("1.5.15")
63+
tempdir <- withr::local_tempdir()
64+
curr_wd <- getwd()
65+
expect_false(file.exists(file.path(tempdir, "_quarto.yml")))
66+
expect_no_error(quarto_create_project(
67+
name = ".",
68+
title = "Test Project",
69+
dir = tempdir,
70+
quiet = TRUE
71+
))
72+
expect_true(file.exists(file.path(tempdir, "_quarto.yml")))
73+
expect_identical(curr_wd, getwd())
74+
expect_identical(
75+
yaml::read_yaml(
76+
file.path(tempdir, "_quarto.yml")
77+
)$project$title,
78+
"Test Project"
79+
)
80+
})

0 commit comments

Comments
 (0)