12

I am interested in providing a command line interface to an R package called Slidify that I am authoring. It uses Rscript and I think that would make it cross-platform. The scripts are stored in the subdirectory inst/slidify. In order to use the script from any directory, I added its path to my .bash_profile as I am on a Mac.

My question is

  1. How should I handle installation of the script in an automated cross-platform way?
  2. How can I make sure that the file permissions are retained in this process?
  3. What should the shebang line for the script be? I am currently using

    #!/usr/bin/Rscript --vanilla --slave

I would appreciate pointers on how to handle this and any examples of R packages that already do it. Just to make sure, I am clear on how this would work, a user would be able to generate a slide deck from slides.Rmd by just running slidify generate slides.Rmd from the command line.

UPDATE:

Here is how I install it on a Mac from the command line. I use the excellent sub library by 37 signals to create the scripts.

echo "$(path/to/clidir/slidify init -)" >> ~/.bash_profile exec bash

Two follow up questions

  1. Can I package these commands into an R function install_slidify_cli?
  2. How can I mirror these commands for Windows users?
W7GVR
  • 1,990
  • 1
  • 18
  • 24
Ramnath
  • 54,439
  • 16
  • 125
  • 152

1 Answers1

8

Lovin' slidify so would be glad to help.

But in short, you can't.

R packages simply cannot install outside of $R_HOME or the chosen library folder. Ship the script in the package, and tell users to copy it. If there was a better way, out littler package with predecessor / alternative to Rscript would long have used it, and roxygen / roxygen2 would also have shipped something.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • I believe `pgfSweave` used to provide such a script, but [apparently](https://github.com/cameronbracken/pgfSweave/commit/cea3c877827bc1a7b7b4e47548ee43fc4b75c814) they later decided it was against the rules to install it automatically. – baptiste Nov 17 '12 at 21:19
  • 2
    They did, and it was *horrible*. At the time I was still running the `cran2deb` autobuilder and it gave me fits. Total cowboy style, totally crazy. Luckily someone else told them off :) – Dirk Eddelbuettel Nov 17 '12 at 21:26
  • Thanks @DirkEddelbuettel I have updated my question with details on how I install the cli from the command line. I would appreciate your thoughts on the two follow up questions raised. – Ramnath Nov 17 '12 at 23:58
  • Dunno. Re 1), I keep `~/bin/` in my path would just softlink from there. Lots of options, and no idea about 2) as that is pretty hopeless territory. – Dirk Eddelbuettel Nov 18 '12 at 00:03
  • Probably will keep it non-windows for now. Given the many options you indicate, what would be you recommend? – Ramnath Nov 18 '12 at 00:11
  • I really don't know. It's open -- maybe ask on r-devel too, or just experiment. This has not settled, and R has no mechanism for it as best as I can tell. – Dirk Eddelbuettel Nov 18 '12 at 01:00
  • Thanks. I will try to post a question on r-devel. – Ramnath Nov 19 '12 at 03:51
  • Can you "emulate" the scripts by using functions instead? Say a script takes 3 arguments, can you not just create a function taking the same 3 arguments and create a "shell" script that essentially gets the 3 arguments, loads the package and calls the function in the package with appropriate arguments? – W7GVR May 19 '15 at 15:55