[inlinedocs] including in-line examples

Simons, Jack (EHS) jack.simons at state.ma.us
Wed Sep 12 16:37:37 CEST 2012


Malcolm, 

Thanks for the helpful explanation.

Jack

Jack Simons Ph.D.
Assistant Director, Children's Behavioral Health Interagency Initiatives
Executive Office of Health and Human Services
1 Ashburton Place, 5th Floor
Boston MA 02108

tel 617-573-1791
fax 617-222-7585
________________________________________
From: inlinedocs-support-bounces at r-forge.wu-wien.ac.at [inlinedocs-support-bounces at r-forge.wu-wien.ac.at] On Behalf Of Cook, Malcolm [MEC at stowers.org]
Sent: Wednesday, September 12, 2012 9:38 AM
To: Cook, Malcolm; Jack Simons; inlinedocs-support at lists.r-forge.r-project.org
Subject: Re: [inlinedocs] including in-line examples

Ooops, Let me amend by own poorly edited post.


Method 1) should read:

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







On 9/12/12 8:37 AM, "Cook, Malcolm" <MEC at stowers.org> wrote:

>
>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-s
>>u
>>pport
>
>_______________________________________________
>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

_______________________________________________
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-support


More information about the Inlinedocs-support mailing list