Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include bash scripts in a package?

I need to include several bash scripts in the R package I'm writing. I'd love to distribute them together with the package, so when a user installs the package via devtools::install_github(...) he/she gets the scripts as well.

I know it is possible, but I don't know how. Including the files in the scripts subdirectory doesn't seem to suffice. I need a means to tell R (or RStudio) to include them.

I use RStudio for development, so I would appreciate a solution that integrates with the "Build package" functionality that RStudio provides.

like image 228
Adam Ryczkowski Avatar asked Sep 15 '17 09:09

Adam Ryczkowski


People also ask

What is $@ in bash?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc.

How do you parameterize a shell script?

A bash shell script have parameters. These parameters start from $1 to $9. When we pass arguments into the command line interface, a positional parameter is assigned to these arguments through the shell. The first argument is assigned as $1, second argument is assigned as $2 and so on...


1 Answers

Simply add whatever you want to the inst/xxx folder in your package.

The folder will get installed as xxx when you compile/publish the package as a library.

You access the files via system.file(), e.g.

system.file('scripts/peak_mem.sh', package='clustertools')

See more details on the R packages by Hadley Wickham

Thank you @Axeman!

like image 108
Adam Ryczkowski Avatar answered Sep 21 '22 22:09

Adam Ryczkowski