[inlinedocs] including in-line examples

Cook, Malcolm MEC at stowers.org
Wed Sep 12 15:37:01 CEST 2012


Suppose I need to define xsquared ...

I would provide an example function in one of two ways:


1) use `structure` when defining the function:

xsquared <- structure( function (x) {x*x},
  ex <- function () {
          Print ifelse(4 == qsquared(2)

2) assign to the ex attribute AFTER defining the function normally.

xsquared <- function (x) {x*x}

attr(xsquared,'ex')<- function () {
print(ifelse(4 == xsquared(2),"looks good","hey!"))
}

Regardless of which method you employ, typing squared to the R prompt
shows the attribute.

> xsquared
function (x) {x*x}
attr(,"ex")
function ()
{
print(ifelse(4 == xsquared(2), "looks good", "hey!"))
}
>




If you do this, then the example will be included in the manual generated
by inline docs.

Matter of style which way you go.

Considerations:

1 confuses my editor (emacs) about where the beginning of the function is.
1 keeps the example next to the code, where it belongs (IMHO).
1 is consistent with using the 'test' attribute to define unit test
functions that svUnit will recognize.


~ Malcolm




On 3/31/12 11:22 AM, "Jack Simons" <jcsimons at verizon.net> wrote:

>Can anyone steer me to a more thorough explanation of how to include
>in-line examples than is found on the package web page at R-forge? ( The
>web page says: "To add inline examples for FUN, use the ex attribute of
>FUN, as shown below." The example shown using "-ex=" is obscure to me.)
>
>thanks for any help
>Jack Simons
>_______________________________________________
>Inlinedocs-support mailing list
>Inlinedocs-support at lists.r-forge.r-project.org
>https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/inlinedocs-su
>pport



More information about the Inlinedocs-support mailing list