Skip to content

Commit 41fd0c9

Browse files
authored
Individual vignettes for different documentation types (#1855)
And generally add more recommendations about what you should write, not just the raw structure.
1 parent 1f009e8 commit 41fd0c9

33 files changed

Lines changed: 1199 additions & 861 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ docs/
1515
/.Rprofile
1616
doc
1717
Meta
18+
.panache-cache

NEWS.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# roxygen2 (development version)
2-
* `vignette("rd-other")` now includes improved advice for documenting S3 generics, classes, and methods, including how to use the new [doclisting](https://doclisting.r-lib.org/) package to automatically list methods for a generic (#1513).
3-
* Added initial support for S7 classes, generics, and methods (#1484).
2+
* `vignette("rd-other")` has been split into individual vignettes: `vignette("rd-datasets")`, `vignette("rd-packages")`, `vignette("rd-S3")`, `vignette("rd-S4")`, and `vignette("rd-R6")`. `vignette("rd")` has been renamed to `vignette("rd-functions")`, and the basics section has been moved to `vignette("roxygen2")`.
3+
* `vignette("rd-S3")` now includes improved advice for documenting S3 generics, classes, and methods, including how to use the new [doclisting](https://doclisting.r-lib.org/) package to automatically list methods for a generic (#1513).
4+
* Added initial support for S7 classes, generics, and methods (#1484). `vignette("rd-S7")` documents best practices.
45
* S7 generics are documented like regular functions.
56
* S7 classes are documented like regular functions, but you can use `@prop` to document additional properties that are not constructor parameters. If multiple classes share one page, use `@prop ClassName@prop_name description` to group properties by class.
67
* S7 methods registered with `method(generic, class) <- fn` are detected automatically and generate usage with `## S7 method for class <ClassName>`.
@@ -440,7 +441,7 @@
440441
441442
* `@includeRmd {path.Rmd}` converts an `.Rmd`/`.md` file to `.Rd` and includes
442443
it in the manual page. This allows sharing text between vignettes,
443-
`README.Rmd`, and the documentation. See `vignette("rd")` for details (#902).
444+
`README.Rmd`, and the documentation. See `vignette("rd-functions")` for details (#902).
444445
445446
* `@order {n}` tag controls the order in which blocks are processed. You can
446447
use it to override the usual ordering which proceeds from the top of
@@ -485,7 +486,7 @@
485486

486487
### R6
487488

488-
roxygen2 can now document R6 classes (#922). See `vignette("rd")` for details.
489+
roxygen2 can now document R6 classes (#922). See `vignette("rd-R6")` for details.
489490

490491
### Markdown improvements
491492

@@ -738,7 +739,7 @@ A big thanks goes to @mikldk for starting on the vignette and motivating me to m
738739
739740
* `@inherits` can now inherit examples (#588).
740741
741-
* `vignette("rd")` received a thorough updating for current best-practices.
742+
* `vignette("rd-functions")` received a thorough updating for current best-practices.
742743
The vignette still needs more work so pull requests are greatly appreciated
743744
(#650).
744745

R/options.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#' * `current_package` `<string>` (read only): name of package being documented.
2626
#'
2727
#' * `rd_family_title` `<list>`: overrides for `@family` titles. See the
28-
#' _rd_ vignette for details: `vignette("rd", package = "roxygen2")`
28+
#' _rd-functions_ vignette for details: `vignette("rd-functions")`
2929
#'
3030
#' * `knitr_chunk_options` `<list>`: default chunk options used for knitr.
3131
#'

R/rd.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
#' @description
44
#' This [roclet] automates the production of the `.Rd` files that
55
#' R uses to document functions, datasets, packages, classes, and more.
6-
#' See `vignette("rd")` for details.
6+
#' See `vignette("rd-functions")` for details.
77
#'
88
#' It is run by default by [roxygenize()].
99
#'
10-
#' @seealso [tags-rd], [tags-rd-data], [tags-rd-oop], [tags-reuse],
10+
#' @seealso [tags-rd-functions], [tags-rd-datasets], [tags-rd-S3], [tags-rd-S4],
11+
#' [tags-rd-S7], [tags-rd-R6], [tags-reuse],
1112
#' [tags-index-crossref] for tags provided by this roclet.
1213
#' @export
1314
#' @examples

R/tag-metadata.R

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,37 @@ tags_rd_desc <- function(tags, section) {
6969

7070
#' Tags for documenting functions
7171
#'
72-
#' @eval tags_rd("rd")
72+
#' @eval tags_rd("rd-functions")
7373
#' @family documentation tags
7474
NULL
7575

7676
#' Tags for documenting datasets
7777
#'
78-
#' @eval tags_rd("rd-data", vignette = "rd-other")
78+
#' @eval tags_rd("rd-datasets")
7979
#' @family documentation tags
8080
NULL
8181

82-
#' Tags for documenting classes
82+
#' Tags for documenting S3
8383
#'
84-
#' @eval tags_rd("rd-oop", vignette = "rd-other")
84+
#' @eval tags_rd("rd-S3")
85+
#' @family documentation tags
86+
NULL
87+
88+
#' Tags for documenting S4
89+
#'
90+
#' @eval tags_rd("rd-S4")
91+
#' @family documentation tags
92+
NULL
93+
94+
#' Tags for documenting S7
95+
#'
96+
#' @eval tags_rd("rd-S7")
97+
#' @family documentation tags
98+
NULL
99+
100+
#' Tags for documenting R6
101+
#'
102+
#' @eval tags_rd("rd-R6")
85103
#' @family documentation tags
86104
NULL
87105

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ When you `roxygenise()` (or `devtools::document()`) your package these comments
5151

5252
To get started, first read `vignette("roxygen2")`. Then read more about the specific package component that you want to generate:
5353

54-
* Start with `vignette("rd")` to learn how document your functions with roxygen2.
54+
* `vignette("rd-functions")` describes how to document your functions with roxygen2.
5555

56-
* `vignette("rd-other")` discusses how to document other things like datasets, the package itself, and the various pieces used by R's OOP systems.
56+
* `vignette("rd-S3")`, `vignette("rd-S4")`, `vignette("rd-R6")`, and `vignette("rd-S7")` discuss documenting the various OOP systems.
57+
58+
* `vignette("rd-datasets")` and `vignette("rd-packages")` cover documenting datasets and the package itself.
5759

5860
* `vignette("rd-formatting")` gives the details of roxygen2's rmarkdown support.
5961

_pkgdown.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ articles:
4444
- title: Documentation
4545
navbar: Documentation
4646
contents:
47-
- rd
48-
- rd-other
47+
- rd-functions
48+
- rd-S3
49+
- rd-S4
50+
- rd-R6
51+
- rd-S7
52+
- rd-datasets
53+
- rd-packages
4954
- reuse
5055
- index-crossref
5156
- rd-formatting

inst/roxygen2-tags.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@
4040
A short description of the purpose of the function. Usually around
4141
a paragraph, but can be longer if needed.
4242
template: "\n${1:A short description...}\n"
43-
vignette: rd
43+
vignette: rd-functions
4444
recommend: true
4545

4646
- name: details
4747
description: >
4848
Additional details about the function. Generally superseded by instead
4949
using a level 1 heading.
5050
template: "\n${1:Additional details...}\n"
51-
vignette: rd
51+
vignette: rd-functions
5252

5353
- name: docType
5454
description: >
@@ -88,22 +88,22 @@
8888
description: >
8989
Embed examples stored in another file.
9090
template: ' ${1:path}.R'
91-
vignette: rd
91+
vignette: rd-functions
9292
recommend: true
9393

9494
- name: examples
9595
description: >
9696
Executable R code that demonstrates how the function works. Code must run
9797
without error.
9898
template: "\n${1:# example code}\n"
99-
vignette: rd
99+
vignette: rd-functions
100100
recommend: true
101101

102102
- name: examplesIf
103103
description: >
104104
Run examples only when `condition` is `TRUE`.
105105
template: " ${1:condition}\n${2:# example code}\n"
106-
vignette: rd
106+
vignette: rd-functions
107107
recommend: true
108108

109109
- name: export
@@ -152,7 +152,7 @@
152152
description: >
153153
Describe a R6 or refClass field.
154154
template: ' ${1:name} ${2:description}'
155-
vignette: rd-oop
155+
vignette: rd-R6
156156
recommend: true
157157

158158
- name: format
@@ -161,7 +161,7 @@
161161
include a description of each column. If not supplied, will be
162162
automatically generated by `object_format()`.
163163
template: ' ${1:description}'
164-
vignette: rd-data
164+
vignette: rd-datasets
165165
recommend: true
166166

167167
- name: import
@@ -257,11 +257,10 @@
257257

258258
- name: method
259259
description: >
260-
Force a function to be recognised as an S3 method. This affects the
261-
default usage and the `NAMESPACE` directive produced by `@export`.
262-
Only needed if automatic detection fails.
260+
If ambiguous, clarify which generic an S3 method belongs too. Only needed
261+
in very rare cases.
263262
template: ' ${1:generic} ${2:class}'
264-
vignette: rd-oop
263+
vignette: rd-S3
265264
recommend: true
266265

267266
- name: name
@@ -280,7 +279,7 @@
280279
description: >
281280
Suppress `.Rd` generation for a block. Use for documentation
282281
blocks that should only be visible in the source code.
283-
vignette: 'rd'
282+
vignette: rd-functions
284283
recommend: true
285284

286285
- name: note
@@ -306,22 +305,23 @@
306305
Document multiple arguments by separating their names with commas
307306
without spaces.
308307
template: ' ${1:name} ${2:description}'
309-
vignette: rd
308+
vignette: rd-functions
310309
recommend: true
311310

312311
- name: prop
313312
description: >
314313
Describe an S7 class property that is not a constructor parameter.
315314
template: ' ${1:name} ${2:description}'
316-
vignette: rd-oop
315+
vignette: rd-S7
317316
recommend: true
318317

319318
- name: R6method
320319
description: >
321320
Document an R6 method that can't be discovered by introspection,
322321
such as methods added via `$set()`.
323322
template: ' ${1:Class}$${2:method}'
324-
vignette: rd-oop
323+
vignette: rd-R6
324+
recommend: true
325325

326326
- name: rawNamespace
327327
description: >
@@ -333,7 +333,7 @@
333333
description: >
334334
Insert literal text directly into the `.Rd` file.
335335
template: ' ${1:rd}'
336-
vignette: rd
336+
vignette: rd-functions
337337

338338
- name: rdname
339339
description: >
@@ -354,15 +354,15 @@
354354
description: >
355355
Describe the function's output. Superseded in favour of `@returns`.
356356
template: ' ${1:description}'
357-
vignette: rd
357+
vignette: rd-functions
358358

359359
- name: returns
360360
description: >
361361
Describe the function's output. Typically will be a 1-2 sentence
362362
description of the output type, but might also include discussion
363363
of important errors or warnings.
364364
template: ' ${1:description}'
365-
vignette: rd
365+
vignette: rd-functions
366366
recommend: true
367367

368368
- name: section
@@ -384,7 +384,7 @@
384384
description: >
385385
Describe the slot of an S4 class.
386386
template: ' ${1:name} ${2:description}'
387-
vignette: rd-oop
387+
vignette: rd-S4
388388
recommend: true
389389

390390
- name: source
@@ -393,7 +393,7 @@
393393
source (if possible) and briefly describe any manipulation that you
394394
performed when importing the data.
395395
template: ' ${1:description}'
396-
vignette: rd-data
396+
vignette: rd-datasets
397397
recommend: true
398398

399399
- name: template
@@ -414,15 +414,15 @@
414414
An explicit `@title` is not usually needed as by default it is taken from
415415
the first paragraph in the roxygen block.
416416
template: ' ${1:title}'
417-
vignette: rd
417+
vignette: rd-functions
418418
recommend: true
419419

420420
- name: usage
421421
description: >
422422
Override the default usage generated by roxygen2. Only needed when
423423
roxygen2 fails to correctly derive the usage of your function.
424424
template: ' ${1:fun}(${2:arg1, arg2 = default, ...})'
425-
vignette: rd
425+
vignette: rd-functions
426426
recommend: true
427427

428428
- name: useDynLib

man/load_options.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rd_roclet.Rd

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

0 commit comments

Comments
 (0)