Including command-line interface in CRAN package?

I wish to include a command-line interface for a function in my R package. It makes a lot of sense in my specific case because this is a package for GWAS, a type of analysis commonly done from command line. This will make it easier for the tool to be accessed by some not familiar with R.

If I build my package with a function that accepts command line arguments via optparse (or another way of passing arguments from the command line), would CRAN allow it, or is this something that can only be published on the project GitHub?

Thanks.

1 Like

That's not something I've ever done but I know there are packages on CRAN helping with this task

Looking into these packages (and similar ones, my list is maybe not exhaustive) and their reverse dependencies might help.

1 Like

Creating a command-line tool from an R package is unfortunately not as straightforward as it is for a Python package. It's not a standard option (e.g. there's no usethis function to set it up).

Off the top of my head, the only package I can think of that provides a command-line tool is littler (GitHub repo). Thus you may be able to learn something from that package. Though it is slightly different than your use case, since it is exporting an executable that wraps R itself, whereas you want an executable that wraps your package's functionality.

The simplest option would be to put your script that uses optparse in the inst/ directory of your package, and then provide documentation that instructs your users to copy this file to a directory on their system's PATH (and to make the file executable).

1 Like