-
Notifications
You must be signed in to change notification settings - Fork 235
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
Documentation for R6 methods #388
Comments
How about also parsing roxygen comments inside the objects that are documented? They seem to be available in the |
Why not one
|
I don't think you want want file per method, because with this style of OO you tend to have lots and lots of little methods. Most docs for js, ruby, python, and java document all methods on a single page. |
Hi! If I may make a couple of suggestions, it would be great something like this (I don't know if I'm defining too many subsections): ClassDescriptionblablabla InheritsBaseClassLink UsageClass$new(param1, ...) Arguments
Public attributes
Public methodsyour structure here Active bindingsActiveBinding1class$activebinding1
class$activebinding1 <- value Description. Parameters
etc. (same structure as methods) Detailsdetails Referencesrefs See alsoblablabla ExamplesGeneral examples |
Sorry to bug, but is there anyone actively working on this? I love roxygen2 and R6 and would very much love and appreciate built-in documentation for my methods (and not just their class). Overall, thanks for the wonderful work you've already done! |
The docstrings from #465 allow also for \code, but you need to escape the , so use a \code. I agree this is a little annoying. I used it as it is similar to how Reference classes are implemented, and expanded from there. An alternative would be to have an R-comment right after the top of the function. When sourcing the code for processing, the comments could be extracted, so then #' could be used. |
@hhoeflin Right, that makes sense. I would say that a #' comment right after the start of the function would be better if possible. I've edited the above to also document inherited methods recursively if they are not overwritten. I'm not sure exactly how to go about submitting a pull request. Should I do it directly here, or as a modification of @hhoeflin 's repository first? Additionally, it seems that this code meets all of the ideas above except:
@hadley Do you think the documentation specified above is adequate, or are you hoping for more discussion about how R6 classes should be documented? |
@epicfarmer what is "this code" that you are talking about? Before you implement a pull request, I think you need to write up an overall design document that describes how documenting R6/RC classes would work, fleshing out the sketches described above. |
@epicfarmer Yes - it doesn't separate active methods from regular ones - but it does label active methods as such. There is certainly quite a few things to be improved from my original implementation. I intended it as a first start towards a discussion. |
@hadley: Sorry, by I edited the code from pull request in #465 . Do you have an example design document from a previous addition? @hhoeflin: That makes sense. Starting with methods as using the same documentation as functions makes sense. However, I think it might be good to additionally have optional fields @ references and @ mutates to document members of the class which are used and modified respectively. |
I don't — but I'd recommend using google docs so that it's easier to comment/collaborate. |
https://drive.google.com/open?id=0BzaZpCcBss4Jd2twbDhNTUdMczA Is something like this what you had in mind? |
Thanks for putting up the design document. Regarding the suggestion of a "mutate" keyword, could you describe its use more closely? Usually for me, accessor methods are defined in OOP in order to abstract away the internal structure of an object. To me, documenting how an accessor method changes internal fields (especially private ones as in your example) seems to be counter to that approach of hiding the internal implementation from the user. |
So, the example was written quickly, and so might not be adequate. I think that you're right in that documenting the internals of the class is not really what we want to do. The original idea behind the mutate keyword, was that we needed a separate field from private = list(
#' Hidden inner workings
.a = 0
),
public = list(
incrementA = function(){
#' Function which modifies hidden inner workings
#' @reference a (Not sure if this should be here or not...)
#' @mutate a Increases a by 1
self$a = self$a+1
}
),
active = list(
a = function(value){
#' public interface to hidden workings
if(missing(value)){
return private$a;
},
private$.a = value
) |
Thanks - yes certainly makes sense to document changes to public fields. |
I think that is out-of-scope for now. It would be better to get something minimal working before adding rarely needed features. |
@hadley Getting something minimal working should definitely come first. If you get a chance, could you glance at the document and make sure its what you had in mind. @hhoeflin Since you already made most of the changes to the code, could you modify the document to include an overview of how you did what you already did? I'm not familiar enough with the structure of roxygen to do it. I've added all the roxygen keywords that seem remotely relevant. I think most of them are out of scope for right now, but I've marked a few that aren't. |
It would be easier to read/comment if it was a properly styled shared google document, not an Rmd uploaded to google drive. |
I forgot that the markdown interface isn't normally part of google documents. https://docs.google.com/document/d/1y8jNDX6tcdWXP4yXNHvwtygYrqoZqSMcHkPheh2pMGY/edit?usp=sharing I'll remove the other one then, so there isn't any confusion. |
As far as documenting methods, perhaps something like this for the Rd: https://docs.google.com/document/d/1axFKclZ5Zf5eX2hnLpLZA0sQh7OACMmmXpP2YT7KJo0/edit?usp=sharing To clarify, for R6Class documentation to be implemented which of the following (or perhaps other things) are needed: how to go from commented R code to Rd documents |
I was thinking more like: \itemize{\code(method1(arg1, arg2, ...))}{
Descriptive stuff and such
\methodtable{Arguments}{
\methoditem{arg1}{...}
\methoditem{arg2}{...}
\methoditem{\dots}{...}
}
\bold{Return value}: something returned
} |
The reason I was thinking of allowing more than one return was so that people could document behaviour where methods store results as members of the class. For example:
With R6 classes, its important to be able to document this sort of behaviour somehow, because its important for users to know where the results are stored in the event that they aren't returned. It would make sense to give it its own section, or to put it with returns, but I think not documenting it at all would be a mistake. (This is the same user as @epicfarmer . I seem to be signed in on another account.) |
Abusing return to document in-place mutation seems like a bad idea to me. |
The gist is that: |
I've made some changes to the document https://docs.google.com/document/d/1axFKclZ5Zf5eX2hnLpLZA0sQh7OACMmmXpP2YT7KJo0/edit?usp=sharing I wanted to avoid using horizontal spacing, but I think its unavoidable. It seems much easier to read the output this way. Does this seem ok to you? |
I think using non-semantic markup in that way is a bad idea. It would be better to keep thinking how we can using existing markup without too many additional hacks. |
By non-semantic markup, are you referring to the switch from subsection to bold with carriage returns, or the use of verb for a tab, or both? |
Both |
In that case, I think the original is the way to go with \bold change to
\emph. Its not visually appealing, but I think its the best we're going to
get in terms of obeying Rd standards. Unless you know of some
non-sectioning keywords that I don't know about?
…On Wed, Mar 22, 2017 at 11:55 AM, Hadley Wickham ***@***.***> wrote:
Both
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#388 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvZG4VGsgT63PMGYfDSnevna9i4aeXaks5roUR2gaJpZM4GKBLh>
.
|
I've updated the document: https://docs.google.com/document/d/1axFKclZ5Zf5eX2hnLpLZA0sQh7OACMmmXpP2YT7KJo0/edit?usp=sharing This acheives a similar effect to the previous pictures, but is less of a hack. @hadley , are there any other parts that feel hacked, which I should try to remove? |
Hi everybody, Cheers, Manuel |
More detailed sketch with @wch: #' My awesome class
#'
#' @export
#' @examples
#' # Integrative examples go here.
MyClass <- R6::R6Class("MyClass", public = list(
#' @section Important things:
#' These are important. More text here.
#' Followed by list of methods.
NULL,
#' Get a single value. Modifies in place.
#' @param key name of key to retrieve
get = function(key) {},
#' Set a single value.
#' @param key name of key to set
#' @param value new value
#' @return old value
set = function(key, val) {}
))
White list of tags specifically for methods
Fields & active bindings just get a description. In class documentation, automatically link to docs for parent class.
Out of scope for now:
Also need to create objects
One page per class. One section for all fields/methods/active binding, |
Is there a way to also cover the $set method? I make very heavy use of it to emulate multiple inheritance. So far i have used a method similar to the one implemented for rcclasses using strings and this also works with "set" (see https://github.com/hhoeflin/roxygen). For an example where it is used, see https://github.com/hhoeflin/hdf5r and the pkgdown doc on https://hhoeflin.github.com/hdf5r One option maybe to also support strings at the beginning of the function instead of or in addition to the comments before the function definition that you propose above? |
@hadley I'm a bit confused by your example in the first part. It seems like you documented the two methods in a few different ways. Are you asking for feedback? (If you are, I think i prefer the nested As far as the scoping goes, this seems like a fine place to start. Do you still need more complete examples before moving on? Also, in general, how can I help move this forward? |
I'm not asking for feedback, I'm just dumping my notes. Unfortunately I don't think there's any way for someone else to push this forward - I want to have a solid mental model of the problem before implementing anything. |
This comment has been minimized.
This comment has been minimized.
As an update, the package I was originally wanting this for is released on cran as ForecastFramework. I have a workaround for documentation that uses roxygen-like syntax, and parses to Rd. I would like to be able to convert that to roxygen if/when this is implemented. It would be helpful if you could keep us updated on your thoughts about which tags will mean what, even if they are currently not implemented. I've been using this post as a guide more or less. |
Hi all, I opened a PR for R6 support: #922. It is a draft, and some things are still coming, but if you give it a try, then feedback is appreciated. Thanks! |
Hi all, |
See #931. |
Thanks for implementing R6 support in roxygen2. Works quite well, except for one feature I have not yet been able to do: How do I link to one particular methods of an R6 class? #' Test R6 class
#' @export
TestR6 = R6Class(
"TestR6",
public = list(
#' @description Example method
myMethodA = function() {1:10}
)
);
#' Test function
#'
#' This function is a wrapper for [TestR6$myMethodA()] or [TestR6#method-myMethodA]
#' or [TestR6#method-myMethodA()], but neither of these links work....
#' @export
myMethodB = function(r) { r$myMethodA() } Neither of the links in the documentation of What is the correct way to link to one particular method? |
Hi @kainhofer, I have the same question before. Please see #955. Basically, it is only possible in HTML output. |
@kainhofer Can you please open a separate issue? We'll be working on R6 again soon, and since I have seen R-core and packages relying on the structure of the help files, we can consider adding proper support for in-page links. |
Should look something like this:
Methods
Method 1
Description.
Parameters
Returns
What the method returns
Example
Rd would look something like:
and similarly for fields.
Parameters, returns, and methods would be optional. If no methods use them, just list usage + (optional) description with bullets. Can also use top-level
@examples
if you want to put all examples in one place.The text was updated successfully, but these errors were encountered: