From 9ceafef190012a23ec496fcf2fd6dee8a6cf4580 Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 11 Jul 2025 16:01:14 -0700 Subject: [PATCH 1/2] Add more project criteria Closes #2133 --- NEWS.md | 5 +++++ R/proj.R | 25 ++++++++++++++++++------- inst/WORDLIST | 4 ++-- man/proj_utils.Rd | 22 +++++++++++++++------- man/use_air.Rd | 2 +- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0e77fc477..fe12ea0f8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,11 @@ * `use_package(min_version = FALSE)` is treated the same as when `min_version` is not specified (#2117, @salim-b). +* usethis's criteria for recognizing a project have expanded to include (#2133): + - a `.vscode/` directory, which Positron or VS Code might create + - a `_quarto.yml` file, typical of a Quarto project + - an `renv.lock` file, which renv creates + # usethis 3.1.0 * `use_vignette()` and `use_article()` support Quarto. The `name` of the new diff --git a/R/proj.R b/R/proj.R index 99945c2ae..58770d82d 100644 --- a/R/proj.R +++ b/R/proj.R @@ -14,18 +14,24 @@ proj_set_ <- function(path) { #' Most `use_*()` functions act on the **active project**. If it is #' unset, usethis uses [rprojroot](https://rprojroot.r-lib.org) to #' find the project root of the current working directory. It establishes the -#' project root by looking for a `.here` file, an RStudio Project, a package -#' `DESCRIPTION`, Git infrastructure, a `remake.yml` file, or a `.projectile` -#' file. It then stores the active project for use for the remainder of the +#' project root by looking for signs such as: +#' * a `.here` file +#' * an RStudio Project, i.e. a `.Rproj` file +#' * an R package, i.e. a `DESCRIPTION` file +#' * a Git repository +#' * a Positron or VS Code workspace, i.e. a `.vscode/` directory +#' * a Quarto project, i.e. a `_quarto.yml` file +#' * an renv project, i.e. a `renv.lock` file +#' usethis then stores the active project for use for the remainder of the #' session. #' #' In general, end user scripts should not contain direct calls to #' `usethis::proj_*()` utility functions. They are internal functions that are #' exported for occasional interactive use or use in packages that extend -#' usethis. End user code should call functions in -#' [rprojroot](https://rprojroot.r-lib.org) or its simpler companion, -#' [here](https://here.r-lib.org), to programmatically detect a project and -#' build paths within it. +#' usethis. End user code should call `here::here()` or other functions from +#' the [here](https://here.r-lib.org) or +#' [rprojroot](https://rprojroot.r-lib.org) packages to programmatically +#' detect a project and build paths within it. #' #' If you are puzzled why a path (usually the current working directory) does #' *not* appear to be inside project, it can be helpful to call @@ -190,6 +196,11 @@ proj_crit <- function() { rprojroot::is_rstudio_project | rprojroot::is_r_package | rprojroot::is_git_root | + # use rprojroot::is_vscode_project at some point in the future + # https://github.com/r-lib/rprojroot/pull/157 + rprojroot::has_dir(".vscode") | + rprojroot::is_quarto_project | + rprojroot::is_renv_project | rprojroot::is_remake_project | rprojroot::is_projectile_project } diff --git a/inst/WORDLIST b/inst/WORDLIST index dc17296e2..b0e7bd17b 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -40,7 +40,6 @@ LinkingTo METACRAN Makefile ORCID -OpenVSX PATs PBC PRs @@ -133,7 +132,6 @@ labelled labelling learnr libgit -libyajl lifecycle ly macbook @@ -164,6 +162,7 @@ readme rebase reconfigures redirections +renv repo repo's repos @@ -207,6 +206,7 @@ useR usethis's ver vm +wc withr xyz xz diff --git a/man/proj_utils.Rd b/man/proj_utils.Rd index 9708d769c..f8a43e7a2 100644 --- a/man/proj_utils.Rd +++ b/man/proj_utils.Rd @@ -61,18 +61,26 @@ execution environment.} Most \verb{use_*()} functions act on the \strong{active project}. If it is unset, usethis uses \href{https://rprojroot.r-lib.org}{rprojroot} to find the project root of the current working directory. It establishes the -project root by looking for a \code{.here} file, an RStudio Project, a package -\code{DESCRIPTION}, Git infrastructure, a \code{remake.yml} file, or a \code{.projectile} -file. It then stores the active project for use for the remainder of the +project root by looking for signs such as: +\itemize{ +\item a \code{.here} file +\item an RStudio Project, i.e. a \code{.Rproj} file +\item an R package, i.e. a \code{DESCRIPTION} file +\item a Git repository +\item a Positron or VS Code workspace, i.e. a \verb{.vscode/} directory +\item a Quarto project, i.e. a \verb{_quarto.yml} file +\item an renv project, i.e. a \code{renv.lock} file +usethis then stores the active project for use for the remainder of the session. +} In general, end user scripts should not contain direct calls to \verb{usethis::proj_*()} utility functions. They are internal functions that are exported for occasional interactive use or use in packages that extend -usethis. End user code should call functions in -\href{https://rprojroot.r-lib.org}{rprojroot} or its simpler companion, -\href{https://here.r-lib.org}{here}, to programmatically detect a project and -build paths within it. +usethis. End user code should call \code{here::here()} or other functions from +the \href{https://here.r-lib.org}{here} or +\href{https://rprojroot.r-lib.org}{rprojroot} packages to programmatically +detect a project and build paths within it. If you are puzzled why a path (usually the current working directory) does \emph{not} appear to be inside project, it can be helpful to call diff --git a/man/use_air.Rd b/man/use_air.Rd index b3774cc90..a8653eaf1 100644 --- a/man/use_air.Rd +++ b/man/use_air.Rd @@ -54,7 +54,7 @@ additional manual step you must take before using Air for the first time: \item For RStudio, follow the \href{https://posit-dev.github.io/air/editor-rstudio.html}{installation guide}. \item For Positron, the \href{https://open-vsx.org/extension/posit/air-vscode}{Air extension} is installed by default and that already includes the Air binary. A typical -Positron user does not need to do anything about installing Air. +Positron user does not need to do anything to install Air. \item For VS Code, install the \href{https://marketplace.visualstudio.com/items?itemName=Posit.air-vscode}{VS Code Extension}. \item For other editors, check to \href{https://posit-dev.github.io/air/editors.html}{see if that editor is supported} by Air. } From 29efac8c81f3213e8342d2f5abe5a3ea4d16f84c Mon Sep 17 00:00:00 2001 From: Jenny Bryan Date: Fri, 11 Jul 2025 16:07:53 -0700 Subject: [PATCH 2/2] Linebreak --- R/proj.R | 1 + man/proj_utils.Rd | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/R/proj.R b/R/proj.R index 58770d82d..eaeed2980 100644 --- a/R/proj.R +++ b/R/proj.R @@ -22,6 +22,7 @@ proj_set_ <- function(path) { #' * a Positron or VS Code workspace, i.e. a `.vscode/` directory #' * a Quarto project, i.e. a `_quarto.yml` file #' * an renv project, i.e. a `renv.lock` file +#' #' usethis then stores the active project for use for the remainder of the #' session. #' diff --git a/man/proj_utils.Rd b/man/proj_utils.Rd index f8a43e7a2..cb8bfff60 100644 --- a/man/proj_utils.Rd +++ b/man/proj_utils.Rd @@ -70,9 +70,10 @@ project root by looking for signs such as: \item a Positron or VS Code workspace, i.e. a \verb{.vscode/} directory \item a Quarto project, i.e. a \verb{_quarto.yml} file \item an renv project, i.e. a \code{renv.lock} file +} + usethis then stores the active project for use for the remainder of the session. -} In general, end user scripts should not contain direct calls to \verb{usethis::proj_*()} utility functions. They are internal functions that are