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

Use #' @examplesIf roxygen directive over if() in the docs #318

Open
6 of 11 tasks
IndrajeetPatil opened this issue Oct 21, 2022 · 12 comments
Open
6 of 11 tasks

Use #' @examplesIf roxygen directive over if() in the docs #318

IndrajeetPatil opened this issue Oct 21, 2022 · 12 comments
Labels
Beginner-friendly 🤝 Friendly for new contributors Core Packages 📦 Discussion and planning about core packages of easystats Documentation 📚

Comments

@IndrajeetPatil
Copy link
Member

IndrajeetPatil commented Oct 21, 2022

There are a couple of reasons to do this:

  1. When there are more than two outputs in if(), only the final one will be displayed in the pkgdown website (cf. Only output from the final example is shown for examples in an if() block r-lib/pkgdown#2175).
#' @examples
#' if (getRversion() > "4.0") {
#'   sd(cars$speed)
#'   sd(cars$dist)
#' }

Screenshot 2022-10-21 at 21 13 07

This is not the case if we use #' @examplesIf instead.

#' @examplesIf getRversion() > "4.0"
#' sd(cars$speed)
#' sd(cars$dist)

Screenshot 2022-10-21 at 21 12 50

  1. This also helps clarify all external dependencies at the top-level (which helps with Mimic and get builds to pass for CRAN's "noSuggests" check in CI/CD #317).

Progress tracker:

  • insight
  • modelbased
  • bayestestR
  • effectsize
  • parameters
  • performance
  • correlation
  • report
  • see
  • datawizard
  • easystats
@IndrajeetPatil IndrajeetPatil added Core Packages 📦 Discussion and planning about core packages of easystats Documentation 📚 Beginner-friendly 🤝 Friendly for new contributors labels Oct 21, 2022
@IndrajeetPatil
Copy link
Member Author

Keep in mind that if your original conditional statement was something like:

#' @examples 
if (requireNamespace("zoo", quietly = TRUE)) {
  ...
}

If you use examplesIf, this won't be included in the output, so it might be a good idea to either namespace all externally used functions, or have a library() call at the top so that the users can exactly reproduce the output.

#' @examplesIf requireNamespace("zoo", quietly = TRUE) 
library(zoo)
 ...

Thanks, @etiennebacher, for bringing up this issue.

IndrajeetPatil added a commit to easystats/datawizard that referenced this issue Oct 21, 2022
mattansb added a commit to easystats/effectsize that referenced this issue Oct 21, 2022
@mattansb
Copy link
Member

Note that in R 4.2.1, the "run examples" is still meh here...

image

@IndrajeetPatil
Copy link
Member Author

Hmm, but this is not too bad. At least, it shows all the output. I am a bit more concerned about some of the outputs not showing up at all on the website.


I can create an issue in rstudio repo to check if they can handle this a bit better. Ideally, the following should not appear in the output:

## Don't show: 
## End(Don't show)
}) # examplesIf

@IndrajeetPatil
Copy link
Member Author

I also checked in the PDF manual, and the examples look good.

IndrajeetPatil added a commit to easystats/modelbased that referenced this issue Nov 4, 2022
@IndrajeetPatil
Copy link
Member Author

Created issue in RStudio to track the suboptimal rendering of examples when run in the IDE: rstudio/rstudio#12318

@IndrajeetPatil
Copy link
Member Author

@rempsyc It would be great if you can also resolve this for report before the next submission.

@rempsyc
Copy link
Sponsor Member

rempsyc commented Jan 29, 2023

Is this necessary when the example is already wrapped in \donttest?

@IndrajeetPatil
Copy link
Member Author

Yes, because CRAN tests \donttest examples in an additional check.

IndrajeetPatil added a commit to easystats/see that referenced this issue Feb 28, 2023
* Get rid of warnings about aes_string

* lints

* Update utils.R

* Use `#' @examplesIf` roxygen directive over `if()`

easystats/easystats#318

* check class correctly

* cleaning more lints

* Update geom_from_list.R

* use devel correlation

* suppress all rstan warnings

* fix a few more warnings

* Update utils.R

* use latest bayestestR

* more dealing with warnings

* suppress rstanarm warnings in tests

* fix more deprecations from ggplot2

* remove ggraph example

since it is producing warnings: thomasp85/ggraph#333

* bump deps

* warnings in examples

* remove NAs

* lintr

* addressing more lints

* use more insight helpers

* more line length linter

* glmmTMB is needed

* Update utils.R

---------

Co-authored-by: Daniel <mail@danielluedecke.de>
@IndrajeetPatil
Copy link
Member Author

bump

@strengejacke
Copy link
Member

Keep in mind that if your original conditional statement was something like:

#' @examples 
if (requireNamespace("zoo", quietly = TRUE)) {
  ...
}

If you use examplesIf, this won't be included in the output, so it might be a good idea to either namespace all externally used functions, or have a library() call at the top so that the users can exactly reproduce the output.

#' @examplesIf requireNamespace("zoo", quietly = TRUE) 
library(zoo)
 ...

Thanks, @etiennebacher, for bringing up this issue.

What about @ExamplesIf require(<package>) ?

@IndrajeetPatil
Copy link
Member Author

Yepp, this is fine. In fact, it's one of the very few situations where require() usage is acceptable.

@bwiernik
Copy link
Contributor

bwiernik commented Oct 2, 2023

Could you explain the difference here? Not sure I'm following

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Beginner-friendly 🤝 Friendly for new contributors Core Packages 📦 Discussion and planning about core packages of easystats Documentation 📚
Projects
None yet
Development

No branches or pull requests

7 participants