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

Add examples for @rdname to 'reuse' vignette #1496

Merged
merged 4 commits into from
Nov 14, 2023
Merged

Conversation

MichaelChirico
Copy link
Contributor

Closes #1495.

I am far from an expert here, and only have a vague sense of when to use one vs. the other myself. The "vibe" I have is @rdname is better when the functions will be "on equal footing" on the shared page, where as @describeIn is more apt for "corollary methods" of a main topic. If that's right, it may be useful to convey that in these sections as well.

@hadley hadley added this to the v7.2.4 milestone Nov 2, 2023
@hadley
Copy link
Member

hadley commented Nov 2, 2023

Thanks for getting me started on this. Can you take a look at my revisions and let me know if they make sense to you?

Copy link
Contributor Author

@MichaelChirico MichaelChirico left a comment

Choose a reason for hiding this comment

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

Thanks, looking much better already!

The functions will be collected and share the same `@title`, `@description`, `@examples`, etc.

There are two basic ways to use it.
You can create a dummy documentation block and then add the functions to it.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Good point. And I think "standalone" is more clear here anyway.

#' @export
ln <- function(x) log(x, exp(1))
```

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we need #' @export tags in the next section (L94-103)?

vignettes/reuse.Rmd Outdated Show resolved Hide resolved
```

Alternatively, you can add docs to an existing function.
This tends to work better if you have a "primary" function with some variants or some helpers.
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'm not sure we're quite there yet, now we have in @rdname

This tends to work better if you have a "primary" function with some variants or some helpers.

Vs in @describeIn

You can document several functions which perform slight variations of a task or which use different defaults

Do we need to distinguish these two "variant"/'variation" use cases further? Or are they ~somewhat~ interchangeable?

Copy link
Member

Choose a reason for hiding this comment

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

TBH I've mostly forgotten what @describeIn does and why you might use it. I think the main difference is that it attempts to build the single description for you by creating a bulleted list. But I'm not sure this is now possible to do in a compelling way, and I think you're generally better off using @rdname with a custom @description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems reasonable enough to me. OTOH, as someone looking at a lot of other peoples' code, it's something I come across fairly often -- it would be nice to point to a canonical reference during code review urging one or the other in each case.

I see 1000s of usages on CRAN:

https://github.com/search?q=lang%3AR+%2F%23%27%5Cs%40describeIn%2F+org%3Acran&type=code

Here's the only file with usage in tidyverse:

https://github.com/tidyverse/reprex/blob/b904f73989583e66cb02fd0199df6cede5be1c3f/R/reprex-undo.R#L22

Vs. 10 packages using it from r-lib:

https://github.com/search?q=lang%3AR+%2F%23%27%5Cs%40describeIn%2F+org%3Ar-lib&type=code

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I've made it more clear that I don't recommend it, and I'll fix the reprex usage momentarily.

Copy link
Member

Choose a reason for hiding this comment

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

@hadley hadley merged commit 00bbfdc into r-lib:main Nov 14, 2023
12 checks passed
@MichaelChirico
Copy link
Contributor Author

Thanks!

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.

Documentation feedback: Difference between @rdname and @describeIn unclear in reuse.Rmd
2 participants