Re: [Rd] Bug in parseNamespaceFile or switch( , ... ) ?

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Sat, 27 Nov 2010 18:50:55 -0500

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.

Duncan Murdoch

>
> Details:
>> # create dummy NAMESPACE file with two bad / one good directives

>> cat("blah( nada )\nblee( nil )\nexport( outDS )\n",file="NAMESPACE")
>> readLines("NAMESPACE")
> [1] "blah( nada )" "blee( nil )" "export( outDS )"
>> parseNamespaceFile("",".") # now parse it
> $imports
> list()
>
> $exports
> [1] "outDS"
>
> $exportPatterns
> character(0)
>
> $importClasses
> list()
>
> $importMethods
> list()
>
> $exportClasses
> character(0)
>
> $exportMethods
> character(0)
>
> $exportClassPatterns
> character(0)
>
> $dynlibs
> character(0)
>
> $nativeRoutines
> list()
>
> $S3methods
> [,1] [,2] [,3]
>
>>
>
> So, it picked up 'export' and ignored the other two lines.
>
>
> Chuck
>
> p.s.
>
>> sessionInfo()
> R version 2.12.0 (2010-10-15)
> Platform: i386-apple-darwin9.8.0/i386 (32-bit)
>
> locale:
> [1] C
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>>
>
>
>
>
>
> Charles C. Berry Dept of Family/Preventive Medicine
> cberry_at_tajo.ucsd.edu UC San Diego
> http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat 27 Nov 2010 - 23:53:24 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 28 Nov 2010 - 08:50:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive