From murdoch at stats.uwo.ca  Tue Oct  6 00:39:21 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Mon, 05 Oct 2009 18:39:21 -0400
Subject: [Rd] unit testing for R packages?
In-Reply-To: <4ACA6DCD.2000609@prodsyse.com>
References: <6c35a4fc0910051201h23e61e39o55bf1de9809bfe29@mail.gmail.com>	<486f230c0910051248xd9d9ab9ie3ac6358184e2989@mail.gmail.com>
	<4ACA5986.5010606@prodsyse.com> <4ACA6AB5.6090806@stats.uwo.ca>
	<4ACA6DCD.2000609@prodsyse.com>
Message-ID: <4ACA7599.5080800@stats.uwo.ca>

On 05/10/2009 6:06 PM, spencerg wrote:
> Hi, Duncan: 
> 
> 
>       Thanks for the warning.  Can you give me a hint of which release 
> might require this?  In particular, will it be R 2.10.0, coming quite 
> soon? 

The alpha version of 2.10.0 lets this pass, and I can't see changing 
that now.  But 2.11.0 (due next spring) may well enforce the rules that 
have been documented but unenforced since before the release of 2.9.0.

Duncan Murdoch

> 
>       Thanks,
>       Spencer
> 
> 
> Duncan Murdoch wrote:
>> On 05/10/2009 4:39 PM, spencerg wrote:
>>> I put unit test in the examples, using "\dontshow" to hide 
>>> "stopifnot".  Many help pages I've written contain code like the 
>>> following:
>>>
>>> A <- functionDocumentedHere()
>>> B <- manuallyComputedAnswer
>>>
>>> \dontshow{stopifnot(}
>>> all.equal(A, B)
>>> \dontshow{)}
>> This will fail in a future release of R, because those aren't valid 
>> expressions within \dontshow{}, which expects R code.  You can achieve 
>> the same effect using the clearer
>>
>> all.equal(A,B)
>> \dontshow{ stopifnot(isTrue(.Last.value)) }
>>
>> Duncan Murdoch
>>
>>>
>>>       I think it helps the documentation to include an example 
>>> comparing a special case computed using a function with a manual 
>>> computation.  However, "stopifnot" contributes nothing to user 
>>> understanding, so I hide it.  One could also use "\dontshow" to hide 
>>> entire examples that check trivial details you think would not 
>>> interest users.
>>>
>>>       Spencer
>>>
>>>
>>> Seth Falcon wrote:
>>>> Hi,
>>>>
>>>> On Mon, Oct 5, 2009 at 12:01 PM, Blair Christian
>>>> <blair.christian at gmail.com> wrote:
>>>>  
>>>>> I'm interested in putting some unit tests into an R package I'm
>>>>> building.  I have seen assorted things such as Runit library, svUnit
>>>>> library, packages
>>>>> with 'tests' directories, etc
>>>>>
>>>>> I grep'd "unit test" through the writing R extensions manual but 
>>>>> didn't find
>>>>> anything.  Are there any suggestions out there?  Currently I have
>>>>> several (a lot?) classes/methods that I keep tinkering with, and I'd
>>>>> like to run a script frequently to check that I don't cause any
>>>>> unforeseen problems.
>>>>>     
>>>> I've had good experiences using RUnit.  To date, I've mostly used
>>>> RUnit by putting tests in inst/unitTests and creating a Makefile there
>>>> to run the tests.  You should also be able to use RUnit in a more
>>>> interactive fashion inside an interactive R session in which you are
>>>> doing development.
>>>>
>>>> The vignette in svUnit has an interesting approach for integrating
>>>> unit testing into R CMD check via examples in an Rd file within the
>>>> package.
>>>>
>>>> + seth
>>>>
>>>>   
>>>
>>
> 
>



[Rd] unit testing for R packages?
Duncan Murdoch