-
Notifications
You must be signed in to change notification settings - Fork 232
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
R6 class support #922
R6 class support #922
Conversation
Apart from the "usual" |
The package now needs the R6 support PR from roxygen: r-lib/roxygen2#922
What about examples? Seems like maybe |
@sckott You can have |
right, that's what I currently do. Should best practice be then to not have examples in public method blocks since they could not be working examples? |
IDK, I think I want to have examples for the methods sometimes, and then have a helper among the test cases to make sure that they run. You still cannot run them with |
15d701e
to
b4b88a3
Compare
@sckott Now we also dump all the method examples into a large |
5772f73
to
e094c65
Compare
@hadley All TODO list items are done. |
We create subclass based on object types. This will let us format the docs differently for different types of objects.
We put this information into the `.r6data` tag. It is stored in a data frame with columns: - `type`: this is always `"method"` now, because we only deal with methods. We will add fields, active bindings and inheritance information later. - `name`: the name of the method, etc. - `file`: name of the file, from the source refs. In theory methods can be defined in different files, but this is not tested yet. - `line`: line number for the start of the method, from the source refs. - `formals`: the `formals()` of the method.
This will let us define a custom page formatter for R6 classes.
It writes out the entries for the main part (i.e. the part that does not belong to methods) first, e.g. description, details, main sections, etc. All tags that are not `@details`, `@param`, `@return` and `@examples` automatically got into the main part. These four tags got into the 'Methods' section, if they appear in the inline comments, i.e. the comments within the class definition. The 'Methods' section has the two parts. First there is a list of all public methods, with in-page links. Then there is one subsection for each method. These appear in the same order as in the source file. For each method we have: - An HTML anchor, so the method can be linked via `[link text](#method-mymethod)` (from the same page), and with `[link text][myclass#method-mymethod]` from other pages. - A "usage" part (not a subsection), with the formals of the method. - Details of the method, the `@details` tags for the method. - An 'Arguments' subsection if the method takes arguments. - A 'Returns' subsection if the method had a `@return` tag. (Max one is allowed.) - An 'Examples' subsection if the method had any `@examples` tags.
Because \return is implicitly a \describe in \arguments. So we should do the same, because then the custom CSS will apply for both the non-R6 arguments and the R6 methods arguments.
This is what R does with the `\arguments()` blocks. Not sure how this looks in the PDF, though.
Look better and this avoids the double rule at the end of the page.
1) Lists the superclasses, e.g. ‘processx::process’ -> ‘callr::r_process’ -> ‘pkgdepends::r_untar_process’ Where each class name is a link. 2) Lists the inherited methods, in HTML. Currently not in text and PDF, because it might be a long list. Seems OK in HTML. Each method name is a link.
Rd2tex does some magic to make this work, but only in a \value{} section, so that does not help us.
The prefix (i.e. _not_ inline) docs may contain @param tags, that the methods automatically inherit, if needed. The methods can also override these arguments, in which case they won't be inherited. These @param tags will be left out from the man page of the class otherwise. If you want to document a function on the same page as the class, e.g. a factory function, then include its arguments in a separate block, the block of the function. This is experimental, and might still change. One drawback is that we cannot inherit currently from or into the method docs, but we can probably fix this later.
* Add 'Usage' and 'Details' headers. * Make sure usage is formatted with the right width of the class$method name. * Omit 'Details' section if no @details tags.
Also change the order of subsections in a method doc to: 1. description 2. usage 3. details 4. examples
Because \tabular does not wrap the text in text and TeX/PDF output.
* Remove row names from data frames. * Save inherited fields and active bindings. * Save superclass information, even if nothing is inherited.
New function: `roxy_warning()`, `roxy_tag_warning()` is a special case of this now.
* Do not link our class, that does not make much sense. * Use the class names, not the block alias.
* Fix shadowed method detection in method list. * Fix class order in hierarchy. * Order methods according to class hierarchy in method list.
e094c65
to
b52ac49
Compare
Thanks @gaborcsardi!! |
Awesome! |
Still coming:
initialize()
/new()
method@field
.@field
as well.get rid of the compulsory(maybe later)@details
tag, in the main part and also before a method@description
as wellnames(formals())
of method arguments matchallow(maybe later)inheritParams()
from methodsallow(maybe later)inheritSection()
from methods, maybeallow(maybe later)@inheritDotParams()
from methodsA test(that) helper to run the code in the examples, because these do notrun in
R CMD check
.\examples{}
block at the end, sothey are tested.
should we used\describe{}
for the list of arguments? Probably....support methods added via(maybe layer)set()
.support user defined(maybe later)clone()
methods.support documenting private methods, fields, active bindings?(maybe later)a vignette?(maybe later)This is the current syntax:
This will generate the following:
This is how it looks in RStudio:
It could look, nicer, e.g. with some extra CSS:
Closes #388.