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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = "aut",
comment = c(ORCID = "0000-0003-0174-9868")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
40 changes: 36 additions & 4 deletions R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand All @@ -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")
#' }
#'
#'
Expand All @@ -32,23 +46,41 @@
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 <type> <name>",
"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(
"1.5.15",
"quarto create project <type> <name> <title>",
"https://quarto.org/docs/projects/quarto-projects.html"
)
}

if (rlang::is_interactive() && !no_prompt) {
folder_msg <- if (name != ".") {
"as a folder named {.strong {name}}"
}

Check warning on line 76 in R/create.R

View check run for this annotation

Codecov / codecov/patch

R/create.R#L74-L76

Added lines #L74 - L76 were not covered by tests
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}}."

Check warning on line 83 in R/create.R

View check run for this annotation

Codecov / codecov/patch

R/create.R#L78-L83

Added lines #L78 - L83 were not covered by tests
))
prompt_value <- tolower(readline(sprintf("Do you want to proceed (Y/n)? ")))
if (!prompt_value %in% c("", "y")) {
Expand All @@ -62,7 +94,7 @@
"project",
type,
name,
name,
title,
"--no-prompt",
"--no-open",
if (is_quiet(quiet)) cli_arg_quiet(),
Expand Down
18 changes: 17 additions & 1 deletion man/quarto_create_project.Rd

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

42 changes: 42 additions & 0 deletions tests/testthat/test-create.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
})