Rscript, where were you all along?

One of the things that I did not like about using R was that there was not “easy” way of calling it in a command sort of way. The test part of my R workflow consisted in going into the R environment and setting everything up from scratch. This was a pain (to say the least). Another problem that overly annoyed me was that I could not get to the script arguments. My solution to these and more problems was to use the -e argument of the R command (not good).

Today I find out that I was overworking myself all along. Since R 1.5.X it has something called Rscritp, that allows the execution of R scripts in a “hashbang” sort of way. This saves me the trouble of having to directly execute R for testing. I can now code a script and add a “#!/usr/bin/Rscript” to the header so it can do the “right” thing.

But it does not end there… The arguments can be  accessed by using the commandArgs() functions. This is OK, but you still have to do quite a lot of analyzing to get the command line parsing right. If there was only something like getoptparse…. It turns out that someone has already been down this road and was kind enough to make an R package for that. I present to you the getopt package. So now I can parse those arguments in a sane way.

This has made my day :)

Advertisements

About joelgranados

I'm fascinated with how technology and science impact our reality and am drawn to leverage them in order to increase the potential of human activity.
This entry was posted in commands, PhD, R and tagged , , , , , , , , , . Bookmark the permalink.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s