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

Support @examplesIf roxygen tag, conditional examples #1236

Merged
merged 4 commits into from
Aug 25, 2020

Conversation

gaborcsardi
Copy link
Member

Unfortunately we need to parse and transform the Rd, so it is not completely trivial. This seems unavoidable.

If the condition is met, then the condition is not shown at all, and the code runs.

If the condition is not met, then it is replaced by if (FALSE), so the example code does not run. We can probably improve this.

@hadley
Copy link
Member

hadley commented Jul 20, 2020

Is there a simple test we could add for this?

@gaborcsardi
Copy link
Member Author

Sure, let me take a look, this might need changes, anyway.

@gaborcsardi gaborcsardi force-pushed the fix/examples-dontshow branch from 91f3936 to 88562e6 Compare August 25, 2020 13:31
@gaborcsardi
Copy link
Member Author

OK, I added tests, and improved the output a bit.

If the condition is false (and not the FALSE constant), then you also get a warning. We might refine this in the future, the intention is that you know about the examples that do not run when building the site.

Example output, false condition:

#' @examplesIf 1 == 0
#' expr

will become

if (FALSE) { # 1 == 0
expr
}

If the condition holds, then the whole boilerplate is removed, and only expr is kept. IDK if we want to show the condition in this case at all, or not.

@hadley hadley merged commit bb3287c into master Aug 25, 2020
@hadley
Copy link
Member

hadley commented Aug 25, 2020

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.

2 participants