Pierre
Pierre

Reputation: 387

How to run a .sh script from R on Windows?

I need to run a .sh script from R on Windows.

To do this, I've tried to call the cygwin executable. Here is my code:

## Define the path to the script .sh and parameters
scriptPath <- "D:/script.sh"
parameters <- c("D:/test/results_","D:/test_text/results_","1","2")

## Define arguments
all_arguments <- c(scriptPath, parameters)

## Run the .sh script
command <- "C:/cygwin64/bin/bash.exe"
output <- system2(command, args=all_arguments, stdout=TRUE)
output

However, I have this error message: "D:/script.sh: line 33: seq: command not found".

Here is the line 33:

for i in $(seq -f "%04g" $step $step $num_end);

On Linux, the script works. Any help would be greatly appreciated.

Upvotes: 0

Views: 987

Answers (1)

James Brusey
James Brusey

Reputation: 365

seq is part of coreutils so your first check should be if your Cygwin install has coreutils installed. You can find out how to install new packages on Cygwin here.

bash under Cygwin will inherit the path from Windows and this doesn't include /usr/bin. To fix this, tell it to behave as if it is invoked at login

all_arguments <- c("-l", scriptPath, parameters)

Note that the filenames will need to be recognisable to Cygwin. See https://cygwin.com/cygwin-ug-net/using.html#cygdrive

Upvotes: 1

Related Questions