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

Allow disabling the wrapping of \dontrun{} blocks with if (FALSE) {} in example sections #2752

Closed
dvg-p4 opened this issue Aug 13, 2024 · 12 comments

Comments

@dvg-p4
Copy link

dvg-p4 commented Aug 13, 2024

We use \dontrun{...} in all of our examples, which require database connections or otherwise should not be automatically run when building our package docs. In R or Rstudio, these unfortunately render as ## Not run: ... ## End(Not run), which at least renders in an easily-ignorable gray. However, pkgdown renders the tags as if (FALSE) {...}, which I think clutters up the page to very little benefit and looks kind of ugly. So, it would be nice if this could be turned off.

@jayhesselberth
Copy link
Collaborator

It's not clear to me what you're advocating for. Hiding the blocks completely? I'm guess not sure what you mean by "turned off".

@dvg-p4
Copy link
Author

dvg-p4 commented Aug 13, 2024

Current:
image

Proposed:
image

@hadley
Copy link
Member

hadley commented Aug 13, 2024

I’d recommend using a different technique like @exampleIf

@hadley hadley closed this as completed Aug 13, 2024
@dvg-p4
Copy link
Author

dvg-p4 commented Aug 13, 2024

I’d recommend using a different technique like @exampleIf

@exampleIf FALSE actually removes the ## Not run: from the R/Rstudio docs, but still leaves the if (FALSE) in pkgdown

@dvg-p4
Copy link
Author

dvg-p4 commented Aug 13, 2024

and @exampleIf 1 == 0 yields if (FALSE) { # 1 == 0

@hadley
Copy link
Member

hadley commented Aug 14, 2024

You should use a real condition that evaluates to TRUE when pkgdown is running.

@dvg-p4
Copy link
Author

dvg-p4 commented Aug 14, 2024

What would that be?

@hadley
Copy link
Member

hadley commented Aug 15, 2024

Presumably you have some idea of when connect() will succeed. You might find https://r-pkgs.org/man.html#sec-man-examples-dependencies-conditional-execution helpful.

@dvg-p4
Copy link
Author

dvg-p4 commented Aug 15, 2024

In short, it won't ever, because the functions in our class require a live connection to an actual database, for which we don't want to put credentials in our package examples.

@dvg-p4
Copy link
Author

dvg-p4 commented Aug 15, 2024

I guess I'm confused as to why pkgdown wants to add this whole if (FALSE) in the first place. The point is to render examples on a webpage; the code isn't going to magically run itself (right?) -- and if someone manually copy-pastes the example code into an R terminal, the if (FALSE) won't stop them cause they can just not copy that part.

@dvg-p4
Copy link
Author

dvg-p4 commented Oct 4, 2024

@hadley Am I misunderstanding something about how these example blocks work, is pkgdown actually evaluating the code when it generates the site?

@hadley
Copy link
Member

hadley commented Oct 4, 2024

Yes, pkgdown runs all the examples.

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

No branches or pull requests

3 participants