Including Command Line Scripts with an R Package

拈花ヽ惹草 提交于 2019-12-19 05:50:45

问题


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?

回答1:


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.



来源:https://stackoverflow.com/questions/13434543/including-command-line-scripts-with-an-r-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!