Skip to content
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

[R] Working on Roxygen documentation #10674

Merged
merged 6 commits into from
Aug 20, 2024
Merged

Conversation

mayer79
Copy link
Contributor

@mayer79 mayer79 commented Aug 2, 2024

Step towards

#9875

After this, only a few R scripts are left for switching to the markdown style.

@@ -10,10 +10,8 @@ S3method(getinfo,xgb.Booster)
S3method(getinfo,xgb.DMatrix)
S3method(length,xgb.Booster)
S3method(predict,xgb.Booster)
S3method(print,xgb.Booster)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's the implication of changing , to .. I know this is generated, but not familiar enough with R type system to understand the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pops up on my side since quite some months. I can easily undo this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with the changes as they are generated. I am just curious about the implications. We run doc gen on the CI as well, not sure what's the cause of the change.

R-package/R/callbacks.R Show resolved Hide resolved
#' at different stages of model training (before / after training, before / after each boosting
#' iteration).
#'
#' @details
#' Arguments that will be passed to the supplied functions are as follows:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave it to @david-cortes for detailed reviews.

R-package/R/callbacks.R Show resolved Hide resolved
@david-cortes
Copy link
Contributor

Some comments:

  • The change of exporting S3 methods as regular functions with dots in the name would introduce issues elsewhere, particularly when dealing with namespaces directly (I can think of incorrectly dispatched functions when using rpy2 for example). These are S3 methods and should be exported as such - not doing otherwise would be a bug.
  • This will create hard-to-solve merge conflicts with other PRs like this: [R] Remove reshape argument in predict #10330
    Would be ideal if these changes could be done after that PR to avoid issues. Perhaps you could base it off the last commit from that branch and then we merge them in sequence.
  • In-doc links like xgb.parameters in predict.xgb.Booster now show with (empty) parentheses in the link text. I personally would prefer them without those parentheses, so that they'd match with the name of the function and the .Rd file. If we take the base R docs as a reference, I see there are some cases where empty parentheses are added, like coef() in the docs for stats::vcov, but the parentheses are not added to the text that forms part of the link (they are plain text next to the link text).
  • While it makes the files easier to inspect visually, I'm not sure it's actually an advantage to have all these docs in markdown mode:
    • We'll likely need to compose docs from different sections in the future (e.g. for parameters in xgboost()), and for some sections the docs are in non-markdown mode due to issues like this: [R] Docs for function arguments format second paragraph as code block #10329
      Would all types of docs play along if they are in different modes?
    • While the syntax is decidely more intuitive at first sight, I'm finding it extremely hard to find any information about how to do something with this new roxygen markdown style or how to address some problem. It's comparatively not as hard to look for something like "roxygen how to add named section" or "roxygen how to create link to function from different package" in a search engine, but there's hardly any results for roxygen's markdown style, and the docs from roxygen developers are not comprehensive to say the least. For example, how would one go around finding the syntax for mathematical equations for this markdown mode if we decide to add such types of docs later?

@mayer79
Copy link
Contributor Author

mayer79 commented Aug 2, 2024

@david-cortes : The file "xgb.DMatrix.R" with the unintended code block in its help file is one of the files I have not worked on yet. Thus, you should not expect it to look great. I am fixing these things on the fly.

As an illustration that such issues are easy to fix, see my latest commit in this PR:

5e57bfe

A good and compact description of rmarkdown in Roxygen

Latex formulas are still the same, e.g., like this:

#' @section Partial Dependence Functions: 
#' 
#' Let \eqn{F: R^p \to R} denote the prediction function that maps the 
#' \eqn{p}-dimensional feature vector \eqn{\mathbf{x} = (x_1, \dots, x_p)}
#' to its prediction. Furthermore, let 
#' \deqn{
#'   F_s(\mathbf{x}_s) = E_{\mathbf{x}_{\setminus s}}(F(\mathbf{x}_s, \mathbf{x}_{\setminus s}))
#' }
#' be the partial dependence function of \eqn{F} on the feature subset
#' \eqn{\mathbf{x}_s}, where \eqn{s \subseteq \{1, \dots, p\}}, as introduced in 
#' Friedman (2001).

@trivialfis
Copy link
Member

I will look into #10330 first to avoid potential conflicts.

@@ -10,10 +10,8 @@ S3method(getinfo,xgb.Booster)
S3method(getinfo,xgb.DMatrix)
S3method(length,xgb.Booster)
S3method(predict,xgb.Booster)
S3method(print,xgb.Booster)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will break existing behaviors

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of the work on the new R interface: #9810

Copy link
Contributor

@david-cortes david-cortes Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be related to the changes in other PRs. In the current master branch, triggering docs build with roxygen doesn't remove the S3 method exports.

Removing the S3 exports would indeed break things elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now added the roxygen tags @method print xgboost and @method print xgb.Booster. This brings the NAMESPACE file back to its original state.

Comment on lines 23 to 24
export(print.xgb.Booster)
export(print.xgboost)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we remove any explicit s3 export statements?

Copy link
Contributor Author

@mayer79 mayer79 Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a commit that fixes the problem by adding the roxygen tags @method print xgboost and @method print xgb.Booster. The NAMESPACE file is now untouched.

@trivialfis
Copy link
Member

Hi @mayer79 , I have merged @david-cortes 's PR, could you please help rebase this one?

@mayer79 mayer79 marked this pull request as draft August 18, 2024 18:19
@mayer79 mayer79 marked this pull request as ready for review August 18, 2024 18:23
@terrytangyuan
Copy link
Member

Removing the S3 exports would indeed break things elsewhere.

Great. Glad that we caught this earlier in the PR.

Copy link
Member

@trivialfis trivialfis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, mostly reformating and reording the existing document, please let me know if there's anything specific that I should pay closer attention.

I will merge the PR if there's no further comment from @david-cortes .

@mayer79
Copy link
Contributor Author

mayer79 commented Aug 19, 2024

Overall looks good to me, mostly reformating and reording the existing document, please let me know if there's anything specific that I should pay closer attention.

I will merge the PR if there's no further comment from @david-cortes .

After the merge, I will try to update the remaining files. Not so much is left now!

@trivialfis trivialfis merged commit b949a4b into dmlc:master Aug 20, 2024
26 of 30 checks passed
@mayer79 mayer79 mentioned this pull request Aug 26, 2024
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants