From ripley at stats.ox.ac.uk  Mon Mar 31 08:49:50 2008
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon, 31 Mar 2008 07:49:50 +0100 (BST)
Subject: [Rd] tests Rin and Rout
In-Reply-To: <47F014DB.6040000@u-paris10.fr>
References: <47F014DB.6040000@u-paris10.fr>
Message-ID: <alpine.LFD.1.00.0803310747400.7538@gannet.stats.ox.ac.uk>

Recommended packages cluster codetools foreign lattice nlme and rpart
have tests, for example.  (As do standard packages grDevices, grid and 
stats.)

On Mon, 31 Mar 2008, Christophe Genolini wrote:

>
>>
>> Generally I find it's good to look at examples that work.  For
>> examples of packages using tests, look at source packages on CRAN.
>> Run the tests on them (using R CMD check), and see what gets produced.
>>
> Do you have the name of a package that use it ? I try the 10 first
> package, and 10 other at random, but none of them use tests...
>>>> Create tests/myPack.R with those lines in it plus lines to actually
>>>> run the code.
>>> Does it mean that each time I change the code, I will have to change
>>> it twice, once in R/ and once in tests/
>>
>> There shouldn't be any duplication.  Just put tests in the tests
>> directory.  That code will be run with your package loaded when you
>> run R CMD check.  If it fails, your package will fail the check.
> Sorry, this is very unclear to me. What do you call "tests" that I have
> to put in the tests directory ?
> Let's take an example : My package is a single function that take the
> square of only positive number. I make a mistake and I forget that it
> has to reject negative number :
>
> sq <- function(x){return(x2)}
>
> Fortunately, I am very conscientious (!) and I did prepare some test :
> - sq(2) should be 4
> - sq(Inf) should be Inf
> - sq(-2) should be NA (on this example, this last test will fail)
>
> At his point :
> sq <- function(x){return(x2)} is in R/main.r
>
> 1) What shall I put in the test file ?
> 2) Cann't I build a Rout file containning the expected results 4 ; Inf;
> NA ?
>
> Thanks for helping
>
> Christophe
>>>   If the code generates errors, your test will fail.  If you want to
>>> see reports of changes to the output, also include
>>> tests/myPack.Rout.save with the known correct versions of the output.
>>>
>> What should the Rout.save looks like ? I mean, what is the syntax of
>> this file ?
>
> It should just be a copy of the Rout file produced from a previous
> trusted run.  R CMD check will ignore certain differences (like changes
> to the date or R version at the top of the file), but will report on
> others.
>
> Duncan Murdoch
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] tests Rin and Rout
Prof Brian Ripley