From murdoch.duncan at gmail.com  Sun Nov 28 23:54:02 2010
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Sun, 28 Nov 2010 17:54:02 -0500
Subject: [Rd] Bug in parseNamespaceFile or switch( , ... ) ?
In-Reply-To: <4CF19DB8.5060706@gmail.com>
References: <Pine.LNX.4.64.1011271448140.23931@tajo.ucsd.edu>
	<4CF1995F.9020006@gmail.com> <4CF19DB8.5060706@gmail.com>
Message-ID: <4CF2DD8A.3080806@gmail.com>

On 27/11/2010 7:09 PM, Duncan Murdoch wrote:
> On 27/11/2010 6:50 PM, Duncan Murdoch wrote:
>> On 27/11/2010 5:58 PM, Charles C. Berry wrote:
>>>
>>> parseNamespaceFile() doesn't seem to detect misspelled directives. Looking
>>> at its code I see
>>>
>>>     	switch(as.character(e[[1L]]),
>>>
>>>     	<lots of args omitted here>,
>>>
>>>     	stop(gettextf("unknown namespace directive: %s",
>>>                     deparse(e)), call. = FALSE, domain = NA))
>>>
>>> but this doesn't seem to function as I expect, viz. to stop with an error
>>> if I type a wrong directive.
>>
>> You're right, there was a typo in parseNamespaceFile.  (The typo was in
>> this line:
>>
>>                   "=", "<-" = {
>>
>> This should have been
>>
>>                   "=" =, "<-" = {
>>
>> Without the extra = sign, the "=" was taken as the default value of the
>> switch, and the stop() was never reached.
>>
>> Conceivably switch() should complain if it is called with more than one
>> default.
>
> I suspect when I fix this it's going to flush out some typos in packages
> on CRAN...

The first fix (to parseNamespaceFile) seems to have caught around 54 
CRAN packages and 13 Bioconductor ones.  Hopefully fixing these typos 
will make the NAMESPACE function more as it was intended.

Fewer packages have been caught so far by the switch() change, but that 
one requires the switch() to actually be executed, so more will show up 
as the packages are used if their tests don't cover all of their code.

Thanks to Brian Ripley for running the tests.  I'll email the 
maintainers to let them know what's going on.

Duncan Murdoch



[Rd] Bug in parseNamespaceFile or switch( , ... ) ?
Duncan Murdoch