This function checks if the current working directory is within a Quarto
project by looking for Quarto project files (_quarto.yml
or _quarto.yaml
).
Unlike get_running_project_root()
, this works both during rendering and
interactive sessions.
See also
get_running_project_root()
for detecting active Quarto rendering
Examples
tmpdir <- tempfile()
dir.create(tmpdir)
find_project_root(tmpdir)
#> NULL
quarto_create_project("test-proj", type = "blog", dir = tmpdir, no_prompt = TRUE, quiet = TRUE)
blog_post_dir <- file.path(tmpdir, "test-proj", "posts", "welcome")
find_project_root(blog_post_dir)
#> [1] "/tmp/RtmpUtmhY0/file229b2ea6fd8/test-proj"
xfun::in_dir(blog_post_dir, {
# Check if current directory is a Quarto project or in one
!is.null(find_project_root())
})
#> [1] TRUE
# clean up
unlink(tmpdir, recursive = TRUE)