From maechler@stat.math.ethz.ch  Thu Oct 21 09:20:44 1999
From: maechler@stat.math.ethz.ch (maechler@stat.math.ethz.ch)
Date: Thu, 21 Oct 1999 10:20:44 +0200 (MET DST)
Subject: error in split... (R 0.65.1) -- and patch (PR#294)
Message-ID: <199910210820.KAA00945@pubhealth.ku.dk>

Thanks for the report.

It is *not* a problem of the quotes  (but how on earth do you get such
			 horrible factor levels with these extra quotes ?)

As a matter of fact, (and as  ?bug.report tries to say)
the bug report should go to  R-bugs, not R-devel;
and preferrably be completely reproducible (using builtin or constructed data)

Here it is, in its reproducible form

a <- gl(3,2,11, lab=LETTERS[1:3])
(aa   <- interaction( a,a))

> split(seq(a), aa)
Error in split(x, f) : second argument must be a factor

The following is a patch (not fully tested, yet):

--- split.R	1999/07/30 14:25:56	1.3
+++ split.R	1999/10/21 08:18:34
@@ -5,7 +5,7 @@
 split.default <-
     function( x, f )
 {
-    f <- as.factor(f)
+    f <- factor(f) # drop extraneous levels
     if(is.null(class(x)))
     {
         retval <- .Internal(split(x, f))


    tony> Just saw the following which looked strange (Thomas, I'll bug you
    tony> about it tommorow...):

    tony> (ctl and group are factors, vectors of strings; ddna is a vector of
    tony> #'s) 

    tony> Does it have to do with the number of quotes?

	
    tony> ctl.x.group <- interaction(ctl,group)
    tony> my.list <- split(ddna,ctl.x.group)
    tony> Error in split(x, f) : second argument must be a factor
    tony> is.factor(ctl.x.group)
    tony> [1] TRUE
    tony> ### Thoughts?  here's ctl and group (trimmed for space):
    tony> ctl
    tony> [1] \"CTL\"    \"CTL\"    \"CTL\"    \"CTL\"    \"CTL\"    \"CTL\"   
    tony> [7] \"CTL\"    \"CTL\"    \"CTL\"    \"CTL\"    \"CTL\"    \"CTL\"   
	      ...

    tony> [1813] \"NONCTL\" \"NONCTL\" \"NONCTL\" \"NONCTL\" \"NONCTL\" \"NONCTL\"
    tony> [1819] \"NONCTL\" \"NONCTL\"
    tony> Levels:  "CTL" "NONCTL" 
    tony> 
    tony> group
    tony> [1] \"L\" \"P\" \"L\" \"P\" \"L\" \"R\" \"L\" \"L\" \"R\" \"R\" ..
    tony> [13] \"R\" \"R\" \"R\" \"L\" \"R\" \"R\" \"R\" \"L\" \"L\" \"L\"..
    .....
    tony> Levels:  "A" "L" "P" "R" 
    tony> 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


error in split... (R 0.65.1) -- and patch (PR#294)
maechler@stat.math.ethz.ch