From spencer.graves at structuremonitoring.com  Mon Jan 20 18:34:28 2014
From: spencer.graves at structuremonitoring.com (Spencer Graves)
Date: Mon, 20 Jan 2014 09:34:28 -0800
Subject: [Rd] Using unit-tests as examples
In-Reply-To: <CABdHhvHuqr9WijK012=N+vP6CHm3zW49H3_H1kUL-s_28hbADA@mail.gmail.com>
References: <CAMGHQ97ct+FQc361micsLrx8CYnFE8WHvCBtVLvWL82bdpDFhA@mail.gmail.com>	<CABdHhvFbSqmyE6zYWvXw5NKJ1NXq4e2aFc8WzPqkiM2d4U445A@mail.gmail.com>	<CAMGHQ94yaG=3mvka4E8RvNf9JyL9-yBPFUiy=iHOzXTFFSTC6g@mail.gmail.com>
	<CABdHhvHuqr9WijK012=N+vP6CHm3zW49H3_H1kUL-s_28hbADA@mail.gmail.com>
Message-ID: <52DD5E24.7060108@structuremonitoring.com>

       You are probably wisest to follow Hadley's recommendation.  
[library(fortunes);  fortune(298)]


       However, my help files contain various constructs of the 
following form:


\dontshow{stopifnot(}
all.equal(fa, fa0)
\dontshow{)}


       where "fa" is returned by a function, and "fa0" is a manual 
computation of what I think the answer should be.


       Spencer Graves


On 1/20/2014 5:33 AM, Hadley Wickham wrote:
> The problem with extracting a single test from a file is going to be
> locating the relevant lines of code and cleanly pulling them out
> (along with any needed supporting code). It might be better to attack
> the problem in the opposite direction by having a roxygen2 directive
> that inserted the block in both the examples and in a special testthat
> file.
>
> Hadley
>
> On Mon, Jan 20, 2014 at 3:32 AM, Alexey Sergushichev
> <alsergbox at gmail.com> wrote:
>> Yes, this may work, but this way I have to have one test per file,
>> which is not very convenient.
>>
>> ---
>> Alexey
>>
>>
>> On Sat, Jan 18, 2014 at 7:43 PM, Hadley Wickham <h.wickham at gmail.com> wrote:
>>> If you're using roxygen2, you can use @example tag to include an
>>> external file into the examples.
>>>
>>> Hadley
>>>
>>> On Sat, Jan 18, 2014 at 7:18 AM, Alexey Sergushichev
>>> <alsergbox at gmail.com> wrote:
>>>> Hi,
>>>>
>>>> Which is the best way to use unit tests as examples for documentation?
>>>> I use testthat, but if there is a good way to do this, for example,
>>>> only with RUnit, it'd still be good to know.
>>>>
>>>> Unit-tests are usually simple and concise, so they are good candidates
>>>> for example code, but I don't want to copy them into documentation and
>>>> maintain by hands. I tried to google how people handle this, but
>>>> didn't find anything.
>>>>
>>>> ---
>>>> Best regards,
>>>> Alexey
>>>>
>>>> ______________________________________________
>>>> R-devel at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>>
>>> --
>>> http://had.co.nz/
>>>



[Rd] Using unit-tests as examples
Spencer Graves