[R] esoteric inconsistency -- intended or not?

From: Bert Gunter <gunter.berton_at_gene.com>
Date: Fri, 07 Nov 2008 11:18:42 -0800

Is the following intended or not?

> func<- function(y) match.call()

> z <- func(y =2)

> z

func(y = 2)

> z[["a"]] <- 5

> z

func(y = 2, 5) ## Note that the second argument **is not** named

## BUT...
> z <- func(y =2)

> z$a <- 5

> z

func(y = 2, a = 5) ## The second argument **is** named

### End of example code ###

The reason I ask is that the man page for [[ specifically says:



Both [[ and $ select a single element of the list. The main difference is that $ does not allow computed indices, whereas [[ does. x$name is equivalent to x[["name", exact = FALSE]]. Also, the partial matching behavior of [[ can be controlled using the exact argument.

[ and [[ are sometimes applied to other recursive objects such as calls and expressions. Pairlists are coerced to lists for extraction by [, but all three operators can be used for replacement.  



 I (mis?)read this as saying the behavior in the code snippets above should produce identical results.

I note that the above inconsistency can be trivially avoided by first coercing the call object to a list, modifying it either way, and then coercing it back to a call object.

I doubt if it makes a difference, but:

> version

               _                                          
platform       i386-pc-mingw32                            
arch           i386                                       
os             mingw32                                    
system         i386, mingw32                              
status         Patched                                    
major          2                                          
minor          8.0                                        
year           2008                                       
month          10                                         
day            23                                         
svn rev        46779                                      
language       R                                          
version.string R version 2.8.0 Patched (2008-10-23 r46779)

Cheers,
Bert Gunter



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 07 Nov 2008 - 19:21:36 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 Sat 08 Nov 2008 - 01:30:22 GMT.

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

list of date sections of archive