Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executable script in R package `inst/`

Tags:

r

I am writing an R package (for internal use, will never be on CRAN). One of my functions calls a shell script containing node.js commands. I've put the file in inst/node_script.sh, so that when the package is installed I can call the script with

system(system.file("./node_script.sh", package = "mypackage"))

This works great on my development machine. But when I install the package on a test machine, node_script.sh is in the proper place, but it drops the executable mode, so I can't run the script without first chmod +x .... Three questions:

  • How can I keep the file permissions on my script file through install?
  • Is there a clean way to set them afterwards? I'm using devtools::install_github
  • Is this even the best way to go about this?
like image 260
gregmacfarlane Avatar asked Sep 14 '25 02:09

gregmacfarlane


1 Answers

I got this working (kind of) by including a 'chmod' command immediately before the call.

node_file <- system.file("./node_script.sh", package = "mypackage")
Sys.chmod(node_file, mode = "0555")
system(node_file)

It seems very hacky to me, and I'd love an alternative.

like image 155
gregmacfarlane Avatar answered Sep 15 '25 14:09

gregmacfarlane