replacing period with underscore in function names

188 views
Skip to first unread message

ram

unread,
Mar 19, 2010, 12:41:31 PM3/19/10
to R for Beginners
I am new to R, but the use of period (.) in function names is quite
contrary to C, C++, Java, and Python languages where period (.) is
used for object qualification. So is there any flags I can set in R to
change the function names using . to a _?
For example, I would like to use as_double instead of as.double.

TIA
--ram

Dan

unread,
Jul 25, 2010, 12:36:03 PM7/25/10
to ram, r-for-b...@googlegroups.com

Hi Ram,

No, there aren't any flags that do that, and it wouldn't be a good
idea. The main reason is that your code would become incompatible with
all other R users' code. Also, seeing as the language supports both
f.g and f_g as a function name, what would this flag do in the
situation where a user has defined is using both names, for different
functions? Such a flag would be inconsistent with the R language. The
function names in R are named what they are, and it's best to just
work with them. I do understand your discomfort. R supports a loose
style of object-oriented programming ("S3") in addition to a very
formal and restrictive one ("S4"). And periods *are* sometimes used in
R to make a sort of class.method structure name. But not always. R is
not C++ nor python nor java.

Note that one can simply assign an existing function definition to a
new variable name:

> f <- function(x) x
> g <- f
> g
function(x) x

so it would be possible to create a list of all functions in the
packages that you currently have loaded, and then traverse that list,
creating duplicate function definitions using underscores instead of
periods. But as indicated above, it would not be a good thing to do.

Dan

>
> TIA
> --ram

Reply all
Reply to author
Forward
0 new messages