From 4c948810d4619b7dcd226f6d5bdd3b54e30ea3bb Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Sat, 9 Jul 2022 21:28:08 -0500 Subject: [PATCH] Hyperlink paths Fixes #1354 --- NEWS.md | 4 ++++ R/rd.R | 9 ++++++++- R/utils.R | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index ada1fda5..49105c88 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # roxygen2 (development version) +* If you have a daily build of RStudio, the lists of changed Rd files are + now clickable so you can immediately see the rendered development + documentation (#1354). + * Automated usage no longer mangles nbsp in default arguments (#1342). * Give useful error if `@describeIn` can't combine docs (#1366). diff --git a/R/rd.R b/R/rd.R index 3c011ec4..81dd8c05 100644 --- a/R/rd.R +++ b/R/rd.R @@ -58,9 +58,16 @@ roclet_output.roclet_rd <- function(x, results, base_path, ..., is_first = FALSE contents <- map_chr(results, format) paths <- file.path(man, names(results)) + names <- unname(map_chr(results, ~ .$get_name()[[1]])) + if (length(names) > 0) { + hrefs <- paste0("rstudio:run:help(`", names, "`)") + } else { + hrefs <- character() + } + # Always check for roxygen2 header before overwriting NAMESPACE (#436), # even when running for the first time - mapply(write_if_different, paths, contents, MoreArgs = list(check = TRUE)) + mapply(write_if_different, paths, contents, href = hrefs) if (!is_first) { # Automatically delete any files in man directory that were generated diff --git a/R/utils.R b/R/utils.R index f74160dc..9fd8e2fd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -61,7 +61,7 @@ nice_name <- function(x) { x } -write_if_different <- function(path, contents, check = TRUE) { +write_if_different <- function(path, contents, href = NULL, check = TRUE) { if (!file.exists(dirname(path))) { dir.create(dirname(path), showWarnings = FALSE) } @@ -87,7 +87,11 @@ write_if_different <- function(path, contents, check = TRUE) { )) FALSE } else { + if (!is.null(href)) { + name <- cli::style_hyperlink(name, href) + } cli::cli_inform("Writing {.path {name}}") + writeBin(charToRaw(contents), path) TRUE }