From 70a24ff5fd09f9ce8a76432b4247e01533afaef1 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 2 Jul 2025 13:18:16 +0200 Subject: [PATCH 1/5] 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 --- R/create.R | 29 ++++++++++++++++++++++--- man/quarto_create_project.Rd | 18 +++++++++++++++- tests/testthat/test-create.R | 42 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 4 deletions(-) diff --git a/R/create.R b/R/create.R index e736e6a3..5838fc91 100644 --- a/R/create.R +++ b/R/create.R @@ -11,7 +11,11 @@ #' #' @param type The type of project to create. As of Quarto 1.4, it can be one of #' `r paste0("\\code{", paste(quarto_project_type, collapse = "}, \\code{"),"}")`. -#' @param name The name of the project and the directory that will be created. +#' @param name The name of the project and the directory that will be created. Special case +#' is to use `name = "."` to create the project in the current directory. In that case provide `title` +#' to set the project title. +#' @param title The title of the project. By default, it will be the name of the project, same as directory name created. +#' or "My project" if `name = "."`. If you want to set a different title, provide it here. #' @param dir The directory in which to create the new Quarto project, i.e. the #' parent directory. #' @@ -23,7 +27,17 @@ #' #' @examples #' \dontrun{ +#' # Create a new project directory in another directory #' quarto_create_project("my-first-quarto-project", dir = "~/tmp") +#' +#' # Create a new project directory in the current directory +#' quarto_create_project("my-first-quarto-project") +#' +#' # Create a new project with a different title +#' quarto_create_project("my-first-quarto-project", title = "My Quarto Project") +#' +#' # Create a new project inside the current directory directly +#' quarto_create_project(".", title = "My Quarto Project") #' } #' #' @@ -32,6 +46,7 @@ quarto_create_project <- function( name, type = "default", dir = ".", + title = name, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL @@ -47,8 +62,16 @@ quarto_create_project <- function( } if (rlang::is_interactive() && !no_prompt) { + folder_msg <- if (name != ".") { + "as a folder named {.strong {name}}" + } cli::cli_inform(c( - "This will create a new Quarto {.emph {type}} project as a folder named {.strong {name}} in {.path {xfun::normalize_path(dir)}}." + paste( + "This will create a new Quarto {.emph {type}} project", + folder_msg, + "in {.path {xfun::normalize_path(dir)}}." + ), + "Project title will be set to {.strong {title}}." )) prompt_value <- tolower(readline(sprintf("Do you want to proceed (Y/n)? "))) if (!prompt_value %in% c("", "y")) { @@ -62,7 +85,7 @@ quarto_create_project <- function( "project", type, name, - name, + title, "--no-prompt", "--no-open", if (is_quiet(quiet)) cli_arg_quiet(), diff --git a/man/quarto_create_project.Rd b/man/quarto_create_project.Rd index 0e3dc95f..eff03d3b 100644 --- a/man/quarto_create_project.Rd +++ b/man/quarto_create_project.Rd @@ -8,13 +8,16 @@ quarto_create_project( name, type = "default", dir = ".", + title = name, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL ) } \arguments{ -\item{name}{The name of the project and the directory that will be created.} +\item{name}{The name of the project and the directory that will be created. Special case +is to use \code{name = "."} to create the project in the current directory. In that case provide \code{title} +to set the project title.} \item{type}{The type of project to create. As of Quarto 1.4, it can be one of \code{default}, \code{website}, \code{blog}, \code{book}, \code{manuscript}, \code{confluence}.} @@ -22,6 +25,9 @@ quarto_create_project( \item{dir}{The directory in which to create the new Quarto project, i.e. the parent directory.} +\item{title}{The title of the project. By default, it will be the name of the project, same as directory name created. +or "My project" if \code{name = "."}. If you want to set a different title, provide it here.} + \item{no_prompt}{Do not prompt to approve the creation of the new project folder.} @@ -50,7 +56,17 @@ your current Quarto version. \examples{ \dontrun{ +# Create a new project directory in another directory quarto_create_project("my-first-quarto-project", dir = "~/tmp") + +# Create a new project directory in the current directory +quarto_create_project("my-first-quarto-project") + +# Create a new project with a different title +quarto_create_project("my-first-quarto-project", title = "My Quarto Project") + +# Create a new project inside the current directory directly +quarto_create_project(".", title = "My Quarto Project") } diff --git a/tests/testthat/test-create.R b/tests/testthat/test-create.R index 02e59e92..2bcb5b35 100644 --- a/tests/testthat/test-create.R +++ b/tests/testthat/test-create.R @@ -36,3 +36,45 @@ test_that("create project only available for 1.4", { variant = "before-1-4" ) }) + +test_that("Create a quarto project in another directory with a different title", { + skip_if_no_quarto("1.4") + tempdir <- withr::local_tempdir() + curr_wd <- getwd() + expect_no_error(quarto_create_project( + name = "test-project", + title = "Test Project", + dir = tempdir, + quiet = TRUE, + no_prompt = TRUE + )) + expect_true(dir.exists(file.path(tempdir, "test-project"))) + expect_identical(curr_wd, getwd()) + expect_identical( + yaml::read_yaml( + file.path(tempdir, "test-project", "_quarto.yml") + )$project$title, + "Test Project" + ) +}) + +test_that("Create a quarto project in the same directory", { + skip_if_no_quarto("1.4") + tempdir <- withr::local_tempdir() + curr_wd <- getwd() + expect_false(file.exists(file.path(tempdir, "_quarto.yml"))) + expect_no_error(quarto_create_project( + name = ".", + title = "Test Project", + dir = tempdir, + quiet = TRUE + )) + expect_true(file.exists(file.path(tempdir, "_quarto.yml"))) + expect_identical(curr_wd, getwd()) + expect_identical( + yaml::read_yaml( + file.path(tempdir, "_quarto.yml") + )$project$title, + "Test Project" + ) +}) From 8998a99fb33ff2c5e4d54db754def3f040daa98f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 2 Jul 2025 13:26:04 +0200 Subject: [PATCH 2/5] Add NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 6c542bcb..4c281018 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # quarto (development version) +- `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. + - `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). - 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. From 58bd8ec516fee2a05a1cfc5face474dedce9bcfd Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 2 Jul 2025 13:31:56 +0200 Subject: [PATCH 3/5] title arg only works for v1.5.15+ --- R/create.R | 11 ++++++++++- tests/testthat/test-create.R | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/R/create.R b/R/create.R index 5838fc91..c81851e2 100644 --- a/R/create.R +++ b/R/create.R @@ -53,10 +53,19 @@ quarto_create_project <- function( ) { check_quarto_version( "1.4", - "quarto create project", + "quarto create project ", "https://quarto.org/docs/projects/quarto-projects.html" ) + # If title is provided, check for Quarto version 1.5.15 or higher + if (title != name) { + check_quarto_version( + "1.5.15", + "quarto create project ", + "https://quarto.org/docs/projects/quarto-projects.html" + ) + } + if (rlang::is_missing(name)) { cli::cli_abort("You need to provide {.arg name} for the new project.") } diff --git a/tests/testthat/test-create.R b/tests/testthat/test-create.R index 2bcb5b35..5cdf3ce4 100644 --- a/tests/testthat/test-create.R +++ b/tests/testthat/test-create.R @@ -38,7 +38,7 @@ test_that("create project only available for 1.4", { }) test_that("Create a quarto project in another directory with a different title", { - skip_if_no_quarto("1.4") + skip_if_no_quarto("1.5.15") tempdir <- withr::local_tempdir() curr_wd <- getwd() expect_no_error(quarto_create_project( @@ -59,7 +59,7 @@ test_that("Create a quarto project in another directory with a different title", }) test_that("Create a quarto project in the same directory", { - skip_if_no_quarto("1.4") + skip_if_no_quarto("1.5.15") tempdir <- withr::local_tempdir() curr_wd <- getwd() expect_false(file.exists(file.path(tempdir, "_quarto.yml"))) From 61e94cc666d823f4dfe6905cd2a2370d344ef144 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux <christophe.dervieux@gmail.com> Date: Wed, 2 Jul 2025 13:32:20 +0200 Subject: [PATCH 4/5] Bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a6b87ad6..5f74af13 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: quarto Title: R Interface to 'Quarto' Markdown Publishing System -Version: 1.4.4.9019 +Version: 1.4.4.9020 Authors@R: c( person("JJ", "Allaire", , "jj@posit.co", role = "aut", comment = c(ORCID = "0000-0003-0174-9868")), From a374d4aabd1854b562bd9d11400f8459ab673421 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux <christophe.dervieux@gmail.com> Date: Wed, 2 Jul 2025 13:45:08 +0200 Subject: [PATCH 5/5] missing name needs to be checked first --- R/create.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/create.R b/R/create.R index c81851e2..43632b31 100644 --- a/R/create.R +++ b/R/create.R @@ -57,6 +57,10 @@ quarto_create_project <- function( "https://quarto.org/docs/projects/quarto-projects.html" ) + if (rlang::is_missing(name)) { + cli::cli_abort("You need to provide {.arg name} for the new project.") + } + # If title is provided, check for Quarto version 1.5.15 or higher if (title != name) { check_quarto_version( @@ -66,10 +70,6 @@ quarto_create_project <- function( ) } - if (rlang::is_missing(name)) { - cli::cli_abort("You need to provide {.arg name} for the new project.") - } - if (rlang::is_interactive() && !no_prompt) { folder_msg <- if (name != ".") { "as a folder named {.strong {name}}"