Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

citation & doi formatting #282

Merged
merged 9 commits into from
Jul 5, 2024
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
18 changes: 15 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@

### Breaking changes

* Simplified rendering for Quarto websites. Previously, the website was rendered into `_quarto/_site` and manually copied over to `docs/`. The new version removes this logic and instead uses the `output-dir` project option. To transition, change `quarto_website.yml` to:
* Simplified rendering for Quarto websites. Previously, the website was rendered
into `_quarto/_site` and manually copied over to `docs/`. The new version removes
this logic and instead uses the `output-dir` project option. To transition, change
`quarto_website.yml` to:
``` yml
project:
output-dir: ../docs/
```

### New features

* `render_docs(freeze = TRUE)` now works correctly when output is `"quarto_website"`. Freezing a document needs to be set either at a project or per-file level. To do so, add to either `quarto_website.yml` or the frontmatter of a file:
* `render_docs(freeze = TRUE)` now works correctly when output is `"quarto_website"`.
Freezing a document needs to be set either at a project or per-file level. To do
so, add to either `quarto_website.yml` or the frontmatter of a file:

``` yml
execute:
freeze: auto
```
* For Quarto websites, `render_docs()` can use the `downlit` package to automatically link function calls to their documentation on the web. Turn off by modifying the `code-link` line in `altdoc/quarto_website.yml`
* For Quarto websites, `render_docs()` can use the `downlit` package to automatically
link function calls to their documentation on the web. Turn off by modifying
the `code-link` line in `altdoc/quarto_website.yml`
* Citation is now formatted with HTML instead of verbatim (#282, Achim Zeileis).
* The `\doi{}` tags in Rd files are now linked once rendered (#282, Achim Zeileis).



### Other changes

Expand Down
15 changes: 13 additions & 2 deletions R/import_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@
tryCatch(
{
name <- .pkg_name(src_dir)
cite <- utils::capture.output(print(utils::citation(name)))
c("# Citation", "", "```verbatim", cite, "```")
cite <- utils::citation(name)
head <- vapply(cite, function(x) {
if (is.null(x$header)) {
""
} else {
paste0(x$header, "\n\n")
}
}, character(1))
if (!is.null(attr(cite, "mheader"))) {
head[1] <- paste0(attr(cite, "mheader"), "\n\n", head[1])
}
cite <- paste0(head, format(cite, style = "html"))
c("# Citation", "", paste(cite, collapse = "\n\n"))
},
error = function(e) NULL)
)
Expand Down
5 changes: 4 additions & 1 deletion R/rd2qmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
# doesn't escape symbols between two $.
tmp <- gsub("\\$", "\\\\$", tmp)

# process \doi{...} tags that were expanded to \Sexpr[results=rd]{tools:::Rd_expr_doi("...")}
tmp <- gsub("(\\\\Sexpr\\[results=rd\\]\\{tools:::Rd_expr_doi\\(\\\")([^\\\"]+)(\\\"\\)\\})", "[doi:\\2](https://doi.org/\\2)", tmp)

# examples: evaluate code blocks (assume examples are always last)
pkg <- .pkg_name(path)
pkg_load <- paste0("library(", pkg, ")")
pkg_load <- paste0("library(\"", pkg, "\")")
idx <- which(tmp == "<h3>Examples</h3>")

if (length(idx) == 1) {
Expand Down
45 changes: 28 additions & 17 deletions tests/testthat/_snaps/docsify/render_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,33 @@
[35] ""
[36] "Some value"
[37] ""
[38] "## Examples"
[38] "## References"
[39] ""
[40] "``` r"
[41] "library(testpkg.altdoc)"
[42] ""
[43] "hello_base()"
[44] "```"
[45] ""
[46] " [1] \"Hello, world!\""
[47] ""
[48] "``` r"
[49] "mtcars$drat <- mtcars$drat + 1"
[50] "head(mtcars[[\"drat\"]], 2)"
[51] "```"
[52] ""
[53] " [1] 4.9 4.9"
[40] "Ihaka R, Gentleman R (1996). R: A Language for Data Analysis and"
[41] "Graphics. <em>Journal of Computational and Graphical Statistics</em>."
[42] "<b>5</b>(3), 299–314."
[43] "[doi:10.2307/139080](https://doi.org/10.2307/139080)"
[44] ""
[45] "## See Also"
[46] ""
[47] "<code>print</code>, <code>hello_r6</code>"
[48] ""
[49] "## Examples"
[50] ""
[51] "``` r"
[52] "library(\"testpkg.altdoc\")"
[53] ""
[54] "hello_base()"
[55] "```"
[56] ""
[57] " [1] \"Hello, world!\""
[58] ""
[59] "``` r"
[60] "mtcars$drat <- mtcars$drat + 1"
[61] "head(mtcars[[\"drat\"]], 2)"
[62] "```"
[63] ""
[64] " [1] 4.9 4.9"

---

Expand Down Expand Up @@ -374,7 +385,7 @@
[31] "## Examples"
[32] ""
[33] "``` r"
[34] "library(testpkg.altdoc)"
[34] "library(\"testpkg.altdoc\")"
[35] ""
[36] ""
[37] "examplesIf_true()"
Expand Down Expand Up @@ -420,7 +431,7 @@
[31] "## Examples"
[32] ""
[33] "``` r"
[34] "library(testpkg.altdoc)"
[34] "library(\"testpkg.altdoc\")"
[35] ""
[36] ""
[37] "examplesIf_false()"
Expand Down
45 changes: 28 additions & 17 deletions tests/testthat/_snaps/docute/render_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,33 @@
[35] ""
[36] "Some value"
[37] ""
[38] "## Examples"
[38] "## References"
[39] ""
[40] "``` r"
[41] "library(testpkg.altdoc)"
[42] ""
[43] "hello_base()"
[44] "```"
[45] ""
[46] " [1] \"Hello, world!\""
[47] ""
[48] "``` r"
[49] "mtcars$drat <- mtcars$drat + 1"
[50] "head(mtcars[[\"drat\"]], 2)"
[51] "```"
[52] ""
[53] " [1] 4.9 4.9"
[40] "Ihaka R, Gentleman R (1996). R: A Language for Data Analysis and"
[41] "Graphics. <em>Journal of Computational and Graphical Statistics</em>."
[42] "<b>5</b>(3), 299–314."
[43] "[doi:10.2307/139080](https://doi.org/10.2307/139080)"
[44] ""
[45] "## See Also"
[46] ""
[47] "<code>print</code>, <code>hello_r6</code>"
[48] ""
[49] "## Examples"
[50] ""
[51] "``` r"
[52] "library(\"testpkg.altdoc\")"
[53] ""
[54] "hello_base()"
[55] "```"
[56] ""
[57] " [1] \"Hello, world!\""
[58] ""
[59] "``` r"
[60] "mtcars$drat <- mtcars$drat + 1"
[61] "head(mtcars[[\"drat\"]], 2)"
[62] "```"
[63] ""
[64] " [1] 4.9 4.9"

---

Expand Down Expand Up @@ -365,7 +376,7 @@
[31] "## Examples"
[32] ""
[33] "``` r"
[34] "library(testpkg.altdoc)"
[34] "library(\"testpkg.altdoc\")"
[35] ""
[36] ""
[37] "examplesIf_true()"
Expand Down Expand Up @@ -411,7 +422,7 @@
[31] "## Examples"
[32] ""
[33] "``` r"
[34] "library(testpkg.altdoc)"
[34] "library(\"testpkg.altdoc\")"
[35] ""
[36] ""
[37] "examplesIf_false()"
Expand Down
41 changes: 26 additions & 15 deletions tests/testthat/_snaps/mkdocs/render_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,33 @@
[35] ""
[36] "Some value"
[37] ""
[38] "## Examples"
[38] "## References"
[39] ""
[40] "``` r"
[41] "library(testpkg.altdoc)"
[42] ""
[43] "hello_base()"
[44] "```"
[45] ""
[46] " [1] \"Hello, world!\""
[47] ""
[48] "``` r"
[49] "mtcars$drat <- mtcars$drat + 1"
[50] "head(mtcars[[\"drat\"]], 2)"
[51] "```"
[52] ""
[53] " [1] 4.9 4.9"
[40] "Ihaka R, Gentleman R (1996). R: A Language for Data Analysis and"
[41] "Graphics. <em>Journal of Computational and Graphical Statistics</em>."
[42] "<b>5</b>(3), 299–314."
[43] "[doi:10.2307/139080](https://doi.org/10.2307/139080)"
[44] ""
[45] "## See Also"
[46] ""
[47] "<code>print</code>, <code>hello_r6</code>"
[48] ""
[49] "## Examples"
[50] ""
[51] "``` r"
[52] "library(\"testpkg.altdoc\")"
[53] ""
[54] "hello_base()"
[55] "```"
[56] ""
[57] " [1] \"Hello, world!\""
[58] ""
[59] "``` r"
[60] "mtcars$drat <- mtcars$drat + 1"
[61] "head(mtcars[[\"drat\"]], 2)"
[62] "```"
[63] ""
[64] " [1] 4.9 4.9"

---

Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/examples/testpkg.altdoc/R/hello_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@
#'
#' @param x A parameter
#'
#' @details
#' Some code with weird symbols: `pl$when(condition)` and `pl$then(output)`
#'
#' Some equations: \eqn{\partial Y / \partial X = a + \varepsilon/2}
#'
#'
#' @return Some value
#' @export
#'
#' @seealso \code{\link[base]{print}}, \code{\link{hello_r6}}
#'
#' @references Ihaka R, Gentleman R (1996).
#' R: A Language for Data Analysis and Graphics.
#' \emph{Journal of Computational and Graphical Statistics}. \bold{5}(3), 299--314.
#' \doi{10.2307/139080}
#'
#' @examples
#' hello_base()
#'
#' mtcars$drat <- mtcars$drat + 1
#' head(mtcars[["drat"]], 2)
hello_base <- function(x = 2) {
print("Hello, world!")
}
9 changes: 9 additions & 0 deletions tests/testthat/examples/testpkg.altdoc/man/hello_base.Rd

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

Loading