Skip to content
Back to formatted view

Raw Message

Message-ID: <421CD833-3D4B-4C8B-8DD9-24A1A6965BF5@auckland.ac.nz>
Date: 2009-05-18T23:02:08Z
From: Rolf Turner
Subject: stringsAsFactors param in expand.grid not working
In-Reply-To: <loom.20090518T220645-789@post.gmane.org>

On 19/05/2009, at 10:20 AM, Steve Lianoglou wrote:

> Hi all,
>
> I've (tried) to look through the bug tracker, and gmane-search the  
> R list to
> see if this has been mentioned before, and it looks like it hasn't.
>
> According to the R 2.9.0 release notes[1], the expand.grid function  
> should now
> take a stringsAsFactor=LOGICAL argument which controls whether or  
> not the
> function coerces strings as factors. While the parameter is indeed  
> in the
> function, a quick examination of the function's source shows that  
> the value
> of this argument is never checked, and all strings are converted to  
> factors
> as a matter of course.
>
> The fix is pretty easy, and I believe only requires changing the  
> `if` check
> here:
>
> if (!is.factor(x) && is.character(x))
>     x <- factor(x, levels = unique(x))
>
> To:
>
> if (!is.factor(x) && is.character(x) && stringsAsFactors)
>     x <- factor(x, levels = unique(x))
>
> I can open a ticket regarding this issue and add this there if  
> necessary.
>
> Thanks,
> -steve
>
> [1] http://article.gmane.org/gmane.comp.lang.r.general/146891

While we're at it --- would it not make sense to have the  
stringsAsFactors
argument (once it's working) of expand.grid() default to options() 
$stringsAsFactors,
rather than to FALSE?

This would make no difference to me personally, since I set
options(stringsAsFactors=FALSE) in my .Rprofile.  But it might make some
people happier ....

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}