I am trying to run a bash file from inside R. So I have the following working fine:
setwd(path.expand("~/Documents/Rcode/"))
system("ls -F")
system('~/Documents/Rcode/GFR_test/run.sh')
So this works absolutely fine as I provided the whole path for the run.sh file. However, this gets tedious when working with long code and many bash files to run. So i needed to create a variable for each sh file as:
myPATH <- "~/Documents/Rcode/GFR_test/"
then to call the run.sh
system(paste(myPATH, 'run.sh'))
Unfortunately this does not work as I get the error:
sh: 1: ~/Documents/Rcode/GFR_test/ : Permission denied
The permission issue is strange as I know I got it right. Can you please help. Thanks
When you use paste
, the default separator is a space. So :
paste(myPATH, 'run.sh')
would give :
~/Documents/Rcode/GFR_test/ run.sh
To suppress the extra space, you either have to add sep=""
to your paste()
, or, better, use paste0
which has a default empty separator (and is a bit faster) :
paste0(myPATH, 'run.sh')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.