Creating commandline tools using R and optparse


Most of the time as a data scientist or data analyst in research, you will be writing your analysis script in RStudio and probably run the script as you go. If you’re really savvy, you might also write your own R packages. If you’re looking to automate analyses or use them as a part of a larger microservices infrastructure in the cloud, you might be looking for a way to commandline tools using R.

In such use case, you might also want to pass optional arguments to the script so you can keep your script quite generic and let commandline arguments do all the configuration. Unfortunately, R does not come with tools to do this easily. In contrast to other scripting languages such as Python, most R users do not have a strong background in software development, so it’s not a use-case discussed very often.

Luckily, there are R packages such as {optparse} that do the heavy lifting for you. For my company blog at SKOPOS ELEMENTS, I have written a short introduction to optparse and how you can use it to create small command line utilities using R, RScript and optparse: So schreibst Du Kommandozeilen-Tools mit R und optparse (as you might have guessed from the title, it is written in German as our main audience is German-speaking; Google Translate or DeepL might be able to help you out.)


Leave a Reply

Your email address will not be published. Required fields are marked *