Skip to content
Prev 229284 / 398500 Next

Using '[' as a function

On 29/07/2010 6:18 PM, chipmaney wrote:
Because it is a function.
Because sapply(example,[,1) would not be syntactically valid.
Its definition is available by typing

`[`

and that shows it to be

.Primitive("[")

Primitive functions are all handled specially by the R evaluator.  In 
this case, you can look at the man page ?"[" which shows a variety of 
different argument signatures that are possible.  R will pass all 
optional arguments to the function, which will then (in special case 
code, because it's a primitive) will figure out which one of those 
syntax patterns is what the user intended.
Primitive functions aren't the best place to start in understanding R, 
because by definition, they're all special cases.  I'd suggest writing 
your own functions with a variety of argument signatures and passing 
them to sapply to see what happens.

Duncan Murdoch