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 @examplesIf snippet to return last value #1659

Open
dgkf opened this issue Sep 18, 2024 · 0 comments
Open

Allow @examplesIf snippet to return last value #1659

dgkf opened this issue Sep 18, 2024 · 0 comments

Comments

@dgkf
Copy link

dgkf commented Sep 18, 2024

Hi! I'm reaching out because of a challenge I'm facing in testex, a package for in-line testing in @examples sections.

It uses a syntax that looks something like this:

#' @examples
#' 1 + 2
#' @test 3
#' @test is.numeric(.)

Tests are generated that run against the last value produced by the previous example expression. However, using @examplesIf is a bit problematic here because it uses withAutoprint() in the generated @examplesIf snippet. This function returns a slightly mutated value, wrapping the result in a list and providing extra information about whether the expression returned visibly.

withAutoprint(1 + 2)
#> 1 + 2
#> [1] 3
.Last.value
#> $value
#> [1] 3
#> 
#> $visible
#> [1] TRUE

Would it be possible to alter the @examplesIf snippet so it returns the result of the examples expression verbatim? If not, I can check for a list with exactly these two names and handle it as a special case, but I don't feel great about introducing heuristics into testing code.

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

1 participant