views:

603

answers:

3

What are some of the R statistical language's "hidden features"?

Similar threads:

+6  A: 

For instance, the number 1.23 is a numerical constant, but the expressions +1.23 and -1.23 are calls to the functions + and -:

> class(quote(1.23))
[1] "numeric"
> class(quote(+1.23))
[1] "call"
> class(quote(-1.23))
[1] "call"
rcs
+5  A: 

Many objects are explicitly "hidden" in R. See, for instance, this question on R-help and this question on the R developer help.

When creating an R package, you have the choice about whether you "export" an object in the NAMESPACE file. Otherwise the object is just intended to be used internally. By convention, many of these names begin with a dot (objects that start with a dot are also "hidden" from the ls() function). Hidden objects can still be accessed, but they don't need to be documented.

You can read more about this in "Writing R Extensions".

Shane
+5  A: 

Adding "L" after a number makes it an integer.

class(3L)
[1] "integer"

You can create non-standard variable name using backquotes.

`a non-standard variable name` <- 1:10
`a non-standard variable name`
[1]  1  2  3  4  5  6  7  8  9 10

You can create your own environments to put variables in. (This can be used for "global" variables, without the danger that they cause.)

myenv <- new.env()
assign("x", 1.2345, envir=myenv)
ls(envir=myenv)
get("x", envir=myenv)
[1] 1.2345
Richie Cotton