Site icon R-bloggers

Little R == r

[This article was first published on Life in Code, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
There’s big R, the R that I use to do most my work, the environment that makes pretty graphics, et. al. It’s like matlab, only cooler. Or more cool. Or less uncool. You can see my prejudices here.

Today i discovered little R. It’s like big R, only little. Holy shit.

Dirk gives a thorough rundown here http://dirk.eddelbuettel.com/code/littler.html Suffice to say, for someone who’s been using pipes and #!/usr/bin constructs for years (though not quite yet decades), this is cooler than cool. One might say, super-cool.

It’s also a nice intro to R for some of the systems geeks out there. Need a million random numbers uniformly distributed between 0 and 1, specified to 7 decimal points? Need it in a file? Need it fast? r can help:
time r -q -e 'for (i in rnorm(1e6)) cat(sprintf("%1.7f\n", i))' >> randomnums  
Or perhaps you have a million numbers in some file that you would like to plot as a histogram, fast, every day, in an automated fashion, from the command line…
cat randomnums | r  -e 'myrandoms <- as.numeric(readLines()); png(filename="myplot.png"); 
plot(histogram(myrandoms)); 
dev.off()' >/dev/null   
No, it won’t mungle strings with the ease of python, but it can chew a spreadsheet and spit it out *fast*. And since it’s a stream, you can always pipe it to/from python. If you ask me, pretty fucking cool.
To leave a comment for the author, please follow the link and comment on their blog: Life in Code.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.