Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba98402
Refine classes for blocks
gaborcsardi Sep 26, 2019
f112f86
Extract information from R6 objects
gaborcsardi Sep 26, 2019
70778a0
Make block_to_rd S3 generic
gaborcsardi Sep 26, 2019
852f2ad
Add block formatter for R6 classes
gaborcsardi Sep 26, 2019
b29181f
Use \describe for arguments and @return
gaborcsardi Sep 26, 2019
5ee5a8c
Put R6 method arguments in a table
gaborcsardi Sep 26, 2019
dd7e35b
Warn for undocumented R6 methods
gaborcsardi Sep 26, 2019
3f32db7
Warn for undocumented and duplicate R6 method parameters
gaborcsardi Sep 26, 2019
f2707b7
Put rule before the R6 method, instead after
gaborcsardi Sep 27, 2019
cc25fb2
Add R6 superclass information
gaborcsardi Sep 27, 2019
3fe5173
Omit \describe for R6 return values, breaks Rd2pdf
gaborcsardi Sep 27, 2019
9a8a94e
Leave out @param from an R6 block, but inherit them into methods
gaborcsardi Sep 30, 2019
7554e81
Support R6 fields via @field
gaborcsardi Oct 1, 2019
a7dd5e5
Support R6 active bindings
gaborcsardi Oct 1, 2019
fd1feed
R6 usage and details improvements
gaborcsardi Oct 1, 2019
d1d81d4
Support @description tags for R6 methods
gaborcsardi Oct 1, 2019
f42fecf
Create big \examples section at end of R6 class page
gaborcsardi Oct 1, 2019
7ba770f
Omit R6 \examples block if empty
gaborcsardi Oct 1, 2019
ac235fd
Add NEWS for R6
gaborcsardi Oct 1, 2019
683457c
Include docs about R6 in the Rd vignette
gaborcsardi Oct 1, 2019
5506727
Add internal docs to the RoxyTopic R6 class
gaborcsardi Oct 1, 2019
ad63dda
Change \tabular -> \describe for R6 arg lists
gaborcsardi Oct 2, 2019
64714f2
Refine R6 data extraction
gaborcsardi Oct 2, 2019
8ed5093
Qualify srcref calls from utils::
gaborcsardi Oct 2, 2019
c0baedb
Uniform warnings
gaborcsardi Oct 2, 2019
418d65f
R6 superclass improvements
gaborcsardi Oct 2, 2019
5527356
Improve superclass information
gaborcsardi Oct 3, 2019
c8feb7f
Add more R6 test cases
gaborcsardi Oct 3, 2019
efff7ea
R6 tests for some edge cases
gaborcsardi Oct 3, 2019
b52ac49
Remove R6 tag if cannot be matched to anything
gaborcsardi Oct 3, 2019
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
Prev Previous commit
Next Next commit
Add internal docs to the RoxyTopic R6 class
  • Loading branch information
gaborcsardi committed Oct 3, 2019
commit 5506727accba22788695e4fb6eae35a76ee35e5a
67 changes: 64 additions & 3 deletions R/topic.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
# An RoxyTopic is an ordered collection of unique rd_sections

#' A `RoxyTopic` is an ordered collection of unique rd_sections
#'
#' @description
#' A `RoxyTopic` object corresponds to a generated `.Rd` file.
#'
#' @param type Section type, a character scalar.
#' @param overwrite Whether to overwrite an existing section. If `FALSE`
#' then the two sections will be merged.
#'
#' @keywords internal

RoxyTopic <- R6::R6Class("RoxyTopic", public = list(

#' @field sections Named list of sections. Each item must be an
#' [rd_section()] object.
sections = list(),

#' @field filename Path to the `.Rd` file to generate.
filename = "",

#' @description Format the `.Rd` file. It considers the sections in
#' particular order, even though Rd tools will reoder them again.
#'
#' @param ... Passed to the `format()` methods of the [rd_section()]
#' objects, the sections.
#' @return Character string.

format = function(...) {
# This has to happen here to get a better order when combining topics
order <- c("backref", "docType", "encoding", "name", "alias", "title",
Expand All @@ -19,30 +42,55 @@ RoxyTopic <- R6::R6Class("RoxyTopic", public = list(
)
},

#' @description Check if an `.Rd` file is valid
#' @return Logical flag, `TRUE` for valid `.Rd` files

is_valid = function() {
# Needs both title and name sections to generate valid Rd
all(self$has_section(c("title", "name")))
},

#' @description Check if an `.Rd` file has a certain section.
#' @return Logical flag.

has_section = function(type) {
type %in% names(self$sections)
},

#' @description Query a section.
#' @return The [rd_section] object representing the section, or `NULL`
#' if the topic has no such section.

get_section = function(type) {
self$sections[[type]]
},

#' @description Query the value of a section. This is the value of
#' the [rd_section] object.
#' @return Value.

get_value = function(type) {
self$get_section(type)$value
},

#' @description Get the Rd code of a section.
#' @return Character vector, one element per line.

get_rd = function(type) {
format(self$get_section(type))
},

#' @description Get the value of the `name` section. This is the name
#' of the Rd topic.
#' @return Character scalar.

get_name = function() {
self$get_value("name")
},

#' @description Query the topics this topic inherits `type` from.
#' @return A character vector of topic names.

inherits_from = function(type) {
if (!self$has_section("inherit")) {
return(character())
Expand All @@ -59,6 +107,9 @@ RoxyTopic <- R6::R6Class("RoxyTopic", public = list(
sources
},

#' @description Query the topix this topic inherits sections from.
#' @return A character vector of topic names.

inherits_section_from = function() {
if (!self$has_section("inherit_section")) {
return(character())
Expand All @@ -67,6 +118,12 @@ RoxyTopic <- R6::R6Class("RoxyTopic", public = list(
self$get_value("inherit_section")$source
},

#' @description Add one or more sections to the topic.
#' @param x Section(s) to add. It may be
#' another `RoxyTopic` object, all of its sections will be added;
#' or an [rd_section] object;
#' or a list of [rd_section] objects to add.

add = function(x, overwrite = FALSE) {
if (inherits(x, "RoxyTopic")) {
self$add(x$sections, overwrite = overwrite)
Expand All @@ -84,8 +141,12 @@ RoxyTopic <- R6::R6Class("RoxyTopic", public = list(
invisible()
},

# Ensures that each type of name (as given by its name), only appears
# once in self$sections - for internal use only.
#' @description Add a section.
#' @details
#' Ensures that each type of name (as given by its name), only appears
#' once in `self$sections`. This method if for internal use only.
#' @param section [rd_section] object to add.

add_section = function(section, overwrite = FALSE) {
type <- section$type
if (self$has_section(type) && !overwrite) {
Expand Down
237 changes: 237 additions & 0 deletions man/RoxyTopic.Rd

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