0

I am submitting a shell script on a remote host that in turn submits an R script, but the error R: command not found or Rscript: command not found (depending whether I tried R CMD BATCH or Rscript).

I have tried submitting in the following ways:

 ssh <remote-host> exec $HOME/test_script.sh

 ssh <remote-host> `sh $HOME/test_script.sh`

The script test_script.sh contains (have tried Rscript as well):

#!/bin/sh

Rscript --no-save --no-restore $HOME/greetme.R

exit 0

The script greetme.R contains only cat("Hello\n").

The reason I am getting flustered is that when I log into the remote-host and submit the original script with sh $HOME/test_script.sh, it runs as intended.

The system specs and R versions for both the local and remote hosts are identical:

> R.version
               _                           
platform       x86_64-unknown-linux-gnu    
arch           x86_64                      
os             linux-gnu                   
system         x86_64, linux-gnu           
status                                     
major          3                           
minor          1.0                         
year           2014                        
month          04                          
day            10                          
svn rev        65387                       
language       R                           
version.string R version 3.1.0 (2014-04-10)
nickname       Spring Dance       

Why is Linux refusing to recognize the commands?

I would prefer solutions using R CMD BATCH or Rscript but if there are known workarounds using littler or %R_TERM% I would like to hear them too.

I used this related question as reference, as well as the documents referenced in the comments: R.exe, Rcmd.exe, Rscript.exe and Rterm.exe: what's the difference?

EDIT for solution:

As @merlin2011 suggested, once I specified the full path in the test_script.sh, everything worked as intended:

#!/bin/sh

/opt/R/bin/Rscript --no-save --no-restore $HOME/greetme.R

exit 0

I got the path also by the provided suggestion:

$ which Rscript
/opt/R/bin/Rscript
Community
  • 1
  • 1
mlegge
  • 6,763
  • 3
  • 40
  • 67

1 Answers1

5

It appears that you have a PATH issue, where R is not on your PATH when you try to run the command through ssh.

If you specify the full path to R and Rscript on the remote host, it should resolve the problem.

If you are not sure what the full path is, try logging into the server and running which R to get the path.

merlin2011
  • 71,677
  • 44
  • 195
  • 329