Skip to content

Commit

Permalink
Update vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Oct 6, 2015
1 parent 612dae1 commit c0f9c95
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
18 changes: 16 additions & 2 deletions vignettes/rd.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## ----, echo = FALSE, message = FALSE-------------------------------------
## ---- echo = FALSE, message = FALSE--------------------------------------
knitr::opts_chunk$set(
comment = "#>",
error = FALSE,
tidy = FALSE
tidy = FALSE,
collapse = TRUE
)

## ------------------------------------------------------------------------
Expand Down Expand Up @@ -181,6 +182,19 @@ times <- function(x, y) x * y
#' Apart from the following special cases...
#' }

## ------------------------------------------------------------------------
#' Basic arithmetic
#'
#' @param x,y numeric vectors.
#' @section Neutral elements:
#' Addition: 0.
add <- function(x, y) x + y

#' @rdname add
#' @section Neutral elements:
#' Multiplication: 1.
times <- function(x, y) x * y

## ------------------------------------------------------------------------
#' @backref src/file.cpp
#' @backref src/file.h
Expand Down
3 changes: 2 additions & 1 deletion vignettes/rd.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
knitr::opts_chunk$set(
comment = "#>",
error = FALSE,
tidy = FALSE
tidy = FALSE,
collapse = TRUE
)
```

Expand Down
21 changes: 20 additions & 1 deletion vignettes/rd.html
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ <h2>Documenting datasets</h2>
#&#39; @source \url{http://www.diamondse.info/}
#&#39; @name diamonds
NULL
#&gt; NULL
</code></pre>

<h2>Documenting packages</h2>
Expand All @@ -552,6 +553,7 @@ <h2>Documenting packages</h2>
#&#39; @docType package
#&#39; @name roxygen2
NULL
#&gt; NULL
</code></pre>

<p>Some notes:</p>
Expand Down Expand Up @@ -637,6 +639,7 @@ <h3>Documenting multiple functions in the same file</h3>
#&#39; @param x,y numeric vectors.
#&#39; @name arith
NULL
#&gt; NULL

#&#39; @rdname arith
add &lt;- function(x, y) x + y
Expand All @@ -647,7 +650,7 @@ <h3>Documenting multiple functions in the same file</h3>

<h2>Sections</h2>

<p>You can add arbitrary sections to the documentation for any object with the <code>@section</code> tag. This is a useful way of breaking a long details section into multiple chunks with useful headings. Section titles should be in sentence case and must be followed a colon. Titles may only take one line.</p>
<p>You can add arbitrary sections to the documentation for any object with the <code>@section</code> tag. This is a useful way of breaking a long details section into multiple chunks with useful headings. Section titles should be in sentence case and must be followed by a colon. Titles may only take one line.</p>

<pre><code class="r">#&#39; @section Warning:
#&#39; Do not operate heavy machinery within 8 hours of using this function.
Expand All @@ -663,6 +666,22 @@ <h2>Sections</h2>
#&#39; }
</code></pre>

<p>Sections with identical titles will be merged.
This is especially useful in conjunction with the <code>@rdname</code> tag:</p>

<pre><code class="r">#&#39; Basic arithmetic
#&#39;
#&#39; @param x,y numeric vectors.
#&#39; @section Neutral elements:
#&#39; Addition: 0.
add &lt;- function(x, y) x + y

#&#39; @rdname add
#&#39; @section Neutral elements:
#&#39; Multiplication: 1.
times &lt;- function(x, y) x * y
</code></pre>

<h2>Back references</h2>

<p>The original source location is added as a comment
Expand Down
24 changes: 23 additions & 1 deletion vignettes/rd.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ To show how everything fits together, the example below is an excerpt from the r
#' @source \url{http://www.diamondse.info/}
#' @name diamonds
NULL
#> NULL
```

## Documenting packages
Expand All @@ -345,6 +346,7 @@ Package documentation should be placed in `pkgname.R`. Here's an example:
#' @docType package
#' @name roxygen2
NULL
#> NULL
```

Some notes:
Expand Down Expand Up @@ -432,6 +434,7 @@ Or, you can create a dummy documentation file by documenting `NULL` and setting
#' @param x,y numeric vectors.
#' @name arith
NULL
#> NULL

#' @rdname arith
add <- function(x, y) x + y
Expand All @@ -442,7 +445,7 @@ times <- function(x, y) x * y

## Sections

You can add arbitrary sections to the documentation for any object with the `@section` tag. This is a useful way of breaking a long details section into multiple chunks with useful headings. Section titles should be in sentence case and must be followed a colon. Titles may only take one line.
You can add arbitrary sections to the documentation for any object with the `@section` tag. This is a useful way of breaking a long details section into multiple chunks with useful headings. Section titles should be in sentence case and must be followed by a colon. Titles may only take one line.


```r
Expand All @@ -462,6 +465,25 @@ To add a subsection, you must use the `Rd` `\subsection{}` command, as follows:
#' }
```

Sections with identical titles will be merged.
This is especially useful in conjunction with the `@rdname` tag:


```r
#' Basic arithmetic
#'
#' @param x,y numeric vectors.
#' @section Neutral elements:
#' Addition: 0.
add <- function(x, y) x + y

#' @rdname add
#' @section Neutral elements:
#' Multiplication: 1.
times <- function(x, y) x * y
```


## Back references

The original source location is added as a comment
Expand Down

0 comments on commit c0f9c95

Please sign in to comment.