Skip to content

Commit b1c68f6

Browse files
committed
#484 roclet: enable introduction in Examples section
1 parent 8ee2595 commit b1c68f6

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

R/demo_fun.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' @default The first letter of the alphabet
1111
#' @keywords internal
1212
#' @examplesx
13+
#' @info This is the introduction.
1314
#' @caption A simple example
1415
#' @info This is a simple example showing the default behaviour.
1516
#' @code demo_fun(1)

R/roclet_rdx.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ transform_examplesx <- function(block) {
245245
for (i in seq_along(tags)) {
246246
if (tags[[i]]$tag == "caption") {
247247
if (length(act_example) > 0) {
248+
if (!"caption" %in% names(act_example)) {
249+
act_example$caption <- NA_character_
250+
}
248251
out_tags <- c(
249252
out_tags,
250253
list(roxy_tag("examplex", "generated", val = act_example))
@@ -565,7 +568,12 @@ merge.rd_section_examplex <- function(x, y, ...) {
565568
format.rd_section_examplex <- function(x, ...) {
566569
paste0(
567570
"\\section{Examples}{\n",
568-
paste0("\\subsection{", x$value$caption, "}{", x$value$contents, "}", collapse = "\n"),
571+
paste0(if_else(
572+
is.na(x$value$caption),
573+
x$value$contents,
574+
paste0("\\subsection{", x$value$caption, "}{", x$value$contents, "}")
575+
),
576+
collapse = "\n"),
569577
"}\n"
570578
)
571579
}

man/demo_fun.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/roclet_rdx/test_fun.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/fixtures/test_fun.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#' @default The first letter of the alphabet
1212
#'
1313
#' @examplesx
14+
#' @info This is the introduction.
1415
#' @caption First example
1516
#' @info This example shows the default behavior of the function.
1617
#' @code

0 commit comments

Comments
 (0)