-
Notifications
You must be signed in to change notification settings - Fork 235
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
Dynamic examples, take two #962
Comments
Just to be clear, I'm imagining that #' @dynex
#' interactive()
#' name <- readline("name> ")
#' cat("hello", name) would become #' @examplesIf interactive()
#' name <- readline("name> ")
#' cat("hello", name) |
Since the release is delayed and you've already implemented this, maybe it's worth trying to get into 7.0.0? |
I think it would be better to experiment with this a bit, I already found an issue with the printing, only the last expression within the It is pretty easy to add the |
Right, it does not matter which line you put the condition, roxygen2 parses them the same way, and yeah, we would call it |
This seems good, except that #' @examples
#' \dontshow{ if (pingr::is_online()) withAutoprint(\{ }
#' ...
#' \dontshow{ \}) } |
|
FWIW I started using this approach in pkgsearch, but in the end had to call an internal helper function, to make it work on older R: pkgdown looks good to me, somehow auto-magically:
|
pkgdown looks great! I wonder where we can put the helper so any package can easily access it. |
I guess we could put the code in the package itself. Maybe that code can be shortened somehow, and then we can just spell it out in the Rd file. |
OK, we don't really need a helper function it seems, but we can just write this inline: #' @examples
#' \dontshow{ if (pingr::is_online()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ }
#' advanced_search(Maintainer = "ORPHANED")
#' \dontshow{ \}) } With R < 3.4 you won't get nice output from I'll make a PR for a new |
Also, pkgdown needs another look, because now I get: It is possible that I manually tweaked the examples for the nice output, I don't remember. So this probably won't make it into the patch release, and the PR is not that urgent... |
I have now a branch with a PoC to add support for this in pkgdown: https://github.com/r-lib/pkgdown/compare/fix/examples-dontshow Here is some real usage: The output looks quite good, although some empty lines might have been lost: Eventually the roxygen |
PoC implementation is here: https://github.com/gaborcsardi/dynex#readme
\dontshow{}
tags to hide the check for the condition.\Sexpr{}
tags, so don't need to install the package forR CMD build
.@dynex
tags work fine.To include this in roxygen2, we would need to just copy over the code, probably rename the tag to
@examplesIf
, and add support for this in R6 classes.The text was updated successfully, but these errors were encountered: