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")), 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. diff --git a/R/create.R b/R/create.R index e736e6a3..43632b31 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,13 +46,14 @@ quarto_create_project <- function( name, type = "default", dir = ".", + title = name, no_prompt = FALSE, quiet = FALSE, quarto_args = NULL ) { check_quarto_version( "1.4", - "quarto create project", + "quarto create project ", "https://quarto.org/docs/projects/quarto-projects.html" ) @@ -46,9 +61,26 @@ quarto_create_project <- function( 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( + "1.5.15", + "quarto create project ", + "https://quarto.org/docs/projects/quarto-projects.html" + ) + } + 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 +94,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..5cdf3ce4 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.5.15") + 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.5.15") + 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" + ) +})