[R] An example of "overloading" [

Marc Schwartz marc_schwartz at comcast.net
Tue Mar 13 06:09:48 CET 2007


On Mon, 2007-03-12 at 21:28 -0700, Sender wrote:
> Hello:
> 
> Could anyone point me to a nice example where someone has created methods
> for "[" on a user defined Class?
> 
> I looked at the package Matrix but that was a little daunting. I'm looking
> for someone a little more introductory. I've tried to search the help
> section and the web but its difficult since "[" isn't searchable.
> 
> Thanks in advance!
> 
> Greg

You might want to look at this thread from last year:

  http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77057.html

  http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77060.html

  http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77059.html

  http://finzi.psych.upenn.edu/R/Rhelp02a/archive/77102.html


You can also review the existing methods defined for '[' in your current
installation by using:

  methods("[")

It may be easiest to then review the code for a given method by using
something like the following as an example:

  getAnywhere("[.data.frame")


BTW, for searching the R help files, REGEX's are used, so for "[", you
would need:

  help.search("\\[")

since '[' is a special character in regular expressions and you need to
escape it to search on the literal character. In R, you need to double
the '\' to be interpreted properly.

HTH,

Marc Schwartz



More information about the R-help mailing list