> > 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]]
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
>>>>> "CG" == Christophe Genolini <cgenolin at u-paris10.fr> >>>>> on Mon, 31 Mar 2008 00:31:55 +0200 writes:>> >> 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. >> CG> Do you have the name of a package that use it ? I try CG> the 10 first package, and 10 other at random, but none CG> of them use tests... hmm, I see 219 out 1378 CRAN packages having a 'tests' subdirectory, so it seems you have been a bit unlucky. ;-) Also note that 'R CMD check' runs all the examples in the help files and hence does some testing already without extra tests in ./tests/ Isn't all this is explained nicely in the "Writing R Extensions" Manual? Or are there sections we should expand ? For answering your subsequent questions, you should probably both look at an example package *and* read the 'Writing R Extensions' manual a bit more "closely". BTW: There's an extension to simple regression tests in the ./tests/ directory, namely using the 'RUnit' package for unit tests **IN CONJUNCTION** with ./tests/ : The R Wiki has had a note on that for many months, http://wiki.r-project.org/rwiki/doku.php?id=developers:runit and we have recently nicely implemented a version of this approach in most Rmetrics R packages, e.g. 'fCalendar' as one example. It builds on a simple tests/doRunit.R file and then on content in inst/unitTests/ Martin Maechler, ETH Zurich
Prof Brian Ripley a ?crit :> Recommended packages cluster codetools foreign lattice nlme and rpart > have tests, for example. (As do standard packages grDevices, grid and > stats.) >Thanks for your help. Concerning .Rin, I check all the package you point, but none of them use it. Does someone know a package using .Rin ? Christophe
Christophe Genolini wrote:> Prof Brian Ripley a ?crit : >> Recommended packages cluster codetools foreign lattice nlme and rpart >> have tests, for example. (As do standard packages grDevices, grid and >> stats.) >> > Thanks for your help. > > Concerning .Rin, I check all the package you point, but none of them use it. > Does someone know a package using .Rin ?https://svn.r-project.org/R/trunk/tests/ has isas-tests.Rin and no-segfault.Rin HTH, Tobias