[R] Delete rpart/mvpart cross-validation output

Gabor Grothendieck ggrothendieck at gmail.com
Wed Aug 18 15:38:12 CEST 2010


On Wed, Aug 18, 2010 at 9:14 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> On Fri, Aug 13, 2010 at 1:52 PM, Marie-Hélène Ouellette
> <marieheleneo at gmail.com> wrote:
>> Dear all,
>>
>> I was wondering if there is a simple way to avoid printing the multiple
>> cross-validation automatic output to the console of recursive partitionning
>> functions like rpart or mvpart. For example...
>>
>>> data(spider)
>>>
>> mvpart(data.matrix(spider[,1:12])~herbs+reft+moss+sand+twigs+water,spider,xv="1se",xvmult=100)
>> *X-Val rep : 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18
>> 19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37
>> 38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56
>> 57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75
>> 76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94
>> 95  96  97  98  99  100
>> Minimum tree sizes
>> tabmins
>>  4  6  7  8
>>  2 18 78  2 *
>>
>> ... loosing what's in bold ?
>>
>
> Try this hack:
>
> cat <- function(...) if (..1 != " " && ..1 != "X-Val rep : 1") base::cat(...)
> environment(mvpart) <- .GlobalEnv
>
> mvpart(data.matrix(spider[,1:12])~herbs+reft+moss+sand+twigs+water,spider,xv="1se",xvmult=100)
>

Here it is wrapped into a function:

mvpart <- function(...) {
	cat <- function(...) if (..1 != " " && ..1 != "X-Val rep : 1") base::cat(...)
	mvpart <- mvpart::mvpart
	environment(mvpart) <- environment()
	mvpart(...)
}

mvpart(data.matrix(spider[,1:12])~herbs+reft+moss+sand+twigs+water,spider,xv="1se",xvmult=100)



More information about the R-help mailing list