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

The purpose of @examplesIf #1649

Open
stla opened this issue Aug 27, 2024 · 1 comment
Open

The purpose of @examplesIf #1649

stla opened this issue Aug 27, 2024 · 1 comment

Comments

@stla
Copy link

stla commented Aug 27, 2024

Hello,

The "rd"" vignette claims that the code of the example is not executed during the check when the If condition is FALSE.

However it seems to me that this is not what happens in reality.

This tag includes some \dontshow in the generated Rd code, and according to Writing R Extensions, the \dontshow macro never prevents the execution of the code, it just hides the code to the user, but during R CMD CHECK, this code is executed.

Here is the WRE illustration:

x <- runif(10)       # Shown and run.
\dontrun{plot(x)}    # Only shown.
\dontshow{log(x)}    # Only run.

And I also found the following claim when I googled:

Examples displayed and executed during checks/example runs:
as is
Examples displayed but NOT executed during checks/example runs:
\dontrun{}
Examples NOT displayed but executed during checks/example runs:
\dontshow{}
Examples NOT displayed and NOT executed during checks/example runs:
simply don't type them anywhere ;-)

Best,
Uwe Ligges

Here to be precise. Note this is an old thread (2005).

@mikmart
Copy link
Contributor

mikmart commented Oct 25, 2024

Consider this example:

#' Foo
#' @examplesIf FALSE
#' stop("You can't run this.")
#' @name foo
NULL

The generated .Rd is:

% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/foo.R
\name{foo}
\alias{foo}
\title{Foo}
\description{
Foo
}
\examples{
\dontshow{if (FALSE) withAutoprint(\{ # examplesIf}
stop("You can't run this.")
\dontshow{\}) # examplesIf}
}

You'll notice that the \dontshow macros are wrapping an if statement enclosing the entire examples section. That if statement is not shown but is present in the code that R CMD check runs, disabling the block from being executed.

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

2 participants