Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distributing docopt scripts #18

Open
cysouw opened this issue May 3, 2016 · 3 comments
Open

Distributing docopt scripts #18

cysouw opened this issue May 3, 2016 · 3 comments

Comments

@cysouw
Copy link

cysouw commented May 3, 2016

I'd like to add docopt scripts to my packages, so people working in different environments can use my R-implementations without needing to work inside R themselves. They can then access the routines via a terminal.

R offers a nice option to add executables inside the directory "exec" in an R package. On *nix platforms, these are made executable on install, so they can be immediately used. This seems the primary place to distribute docopt-scripts.

However, my question is how to link these scripts. Their location is rather hidden and difficult to find for non-R-users (within R, you can use the R-function find.package() ).

What would be best-practice?

@trevorld
Copy link
Contributor

trevorld commented Apr 16, 2018

Some ideas on best-practices. I usually either ask my users to manually download executables files of interest from my github repos, mark them executable, and to then either use them locally from the repo folder and/or to copy them to $HOME/bin/ -- simple but clunky. I know some people have packaged Rscripts in the debian "apt" format so users using Debian/Ubuntu can install them using apt install program -- convenient for users but not for developers. Alternatively you can distribute them in R packages and ask your users to install and use a simple shell script abstraction like Rbin::

$ Rbinlist Rpackagename
$ Rbin Rpackagename execfilename [arguments_passed_to_execfilename]

Kind of klunky but you can also give them advice on your README on how add an alias in their .bashrc shell configuration files so that it appears the program is on their path so they can simply type myprogram in their shell::

alias myprogram="Rbin mypackage myprogram"

You can also tell them instructions on how to copy them over to somewhere on their path $HOME/bin/ after package installation::

> file.copy(system.file("exec/myprogram", package="mypackage"), "~/bin/myprogram")

@cysouw
Copy link
Author

cysouw commented Apr 17, 2018

Thanks for the tip! My original comment was from almost two years ago: in the meantime I have settled for the following procedure:

The docopt scripts are added to the exec file in my packages (see for example https://github.com/cysouw/qlcData/). In this way, the whole install and update procedures work through CRAN.

Basically each individual script gives a bash-interface to single functions in the package (e.g. tokenize). In the help file of these functions I then add a note explaining that this function can also be accessed within bash with the following explanation:


There is a bash-executable distributed with this package (based on the docopt package) that let you use this function directly in a bash-terminal. The easiest way to use this executable is to softlink the executable to some directory in your bash PATH, for example /usr/local/bin. To softlink the function tokenize to this directory, use something like the following in your bash terminal:

ln -is `Rscript -e 'cat(file.path(find.package("qlcData"), "exec", "tokenize"))'` /usr/local/bin

then typing tokenize --help in the terminal should give help on this function.

@trevorld
Copy link
Contributor

trevorld commented Apr 17, 2018

In case someone wants to give instructions in R the equivalent R command for the above is::

$ sudo R
> file.symlink(system.file("exec/tokenize", package="qlcData"), "/usr/local/bin")

For users without admin permissions (but were able to install your package locally) would be better to suggest::

> file.symlink(system.file("exec/tokenize", package="qlcData"), "~/bin")

Everything in the above commands should work cross-platform (for more recent versions of Windows) except the location of where to place the symbolic link (although the above two locations should work on most *Nix systems).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants