Learn more about using open source R for big data analysis, predictive modeling, data science and more from the staff of Revolution Analytics.

September 24, 2013

R as a command-line tool for data science

Data Scientist Jeroen Janssens recently published a useful list of 7 data science tools that you can use from the command line. This doesn't just mean they're convenient tools for command-line junkies: it also means you can easily chain them together with data sources for offline, automated processes. Included in the list are JSON processing tools (jq, json2csv), the CSV conversion tool csvkit, XML extraction tools (scrape, xml2json), and a file-level row-sampling tool (sample). The analysis tool on the list is, as you might expect, R.

Janssens created a bash script called Rio to call R from the command line, but in fact there are already several options for using R in shell scripts and pipelines. You can redirect standard input and standard output with R as is typical with most command-line utilities, but R also provides a standard script — R CMD BATCH — for running R commands from a file and capturing the output in another file. You can even use R as a shell-scripting language using notation like #! /usr/local/Rscript at the top of an executable script file. (There's also littler, another handy command-line front-end for R.)

R is definitely an powerful tool for data science, and there are several options for making it part of your command-line workflow.