I am currently trying to run an R file as an Rscript file. I have the following code inside a script.sh file:
#!/bin/bash
cd documents
module load r
#!/usr/bin/env Rscript
mem2 <- 4+5
packageVersion("data.table")
save.image("OUT.RData")
However, it appears that after running this using qsub script.sh, it comes back with errors saying how several commands were not recognized. Am I doing this wrong? Thanks!
I think you're looking for a "Here document" in the shell. That allows text to be passed to another interpreter. For example:
#!/bin/bash
cd documents
module load r
/usr/bin/env Rscript -<<EOF
mem2 <- 4+5
packageVersion("data.table")
save.image("OUT.RData")
EOF
Here, the Rscript is called (from /usr/bin/env) and on the standard input, all of the subsequent lines are passed until the marker (here, EOF) is seen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With