Why?

April 1, 2015

Standardising Function Names in R

Filed under: R — csgillespie @ 12:01 am

The renamer Package

Tired of the disparate naming systems in R? Then this is the package for you.

Installing the package

The package is located in my drat. To install

install.packages("renamer", repos="http://csgillespie.github.io/drat", type="source")

or if you have drat installed

drat::addRepo("csgillespie")
install.packages("renamer", type="source")

The source is available on my github page

Example: The CamelCaseR

If have an unnatural fear of underscores, that prevents the use of ggplot2, then you are saved

## Assumes you have ggplot2 installed
library(renamer)
camelCase("ggplot2")

Then

data(cars)
ggplot(cars) + geomPoint(aes(speed, dist))

Example: The UnderscoreR

If you’ve want to try the excellent `drat` package, but you find the lack of underscores
unnerving, you too are saved

library(renamer)
install.packages("drat", repos="http://eddelbuettel.github.io/drat")
under_score("drat")

The examples on the drat homepage become

add_repo("eddelbuettel")
insert_package("drat_0.0.1.tar.gz")

Future directions

Now that the problem with the R naming system has been solved, the next logical step is
to remove differences *between* languages

  • lisp` converter – randomly add brackets to all functions
  • python – insert spaces/tabs on every line
  • FORTRAN – all code starts on the eighth column
    • Advertisements

8 Comments »

  1. Would it be possible to deal with the unnecessary periods in names, like make.names and, dare I suggest, data.frame? I know R’s system for handling method dispatching relies on looking at names, so it might be difficult.

    Comment by Nathan — April 1, 2015 @ 3:00 pm

    • I don’t think it’s possible, since I can’t think of a way of testing whether something is an S3 object

      Comment by csgillespie — April 2, 2015 @ 9:16 pm

  2. Excellent April Fool’s 😛

    Comment by Fr. — April 2, 2015 @ 12:02 am

  3. Fortran: Don’t forget the continuation character in column 7 for multiple lines and the “C” in column 1 for comments. Gosh, am I dating myself or what!

    Comment by ptm12983 — April 2, 2015 @ 12:37 am

  4. Very nicely done! Very subtle.

    Comment by David — April 2, 2015 @ 6:24 am

    • Perhaps a bit too subtle

      Comment by csgillespie — April 2, 2015 @ 9:13 pm

      • Given that auto-refactoring and syntax beautify are, sort of, standard parts of many C/C++/java toolsets, yeah. Munging object names, with a bit of AWK, isn’t too far past that.

        Comment by Robert Young — April 3, 2015 @ 1:08 pm

  5. […] Function Names in R (renamer) Tired of the disparate naming systems in R? Then this is the package for […]

    Pingback by R Packages worth a look | Data Analytics & R — April 5, 2015 @ 9:08 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: