Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I call system functions in R that clearly work in my terminal?

Tags:

r

system

I am trying to call system functions in R. I am using a mac. If I pass a built-in function (e.g. ln), it works no problem:

command <- "ls"
cat(command, "\n")
try(system(command))

I get a list of the directory.

However, if I install functions from third parties (e.g. binaries), it doesn't work (even if it works in the terminal).

command <- "bedtools ..."
cat(command, "\n")
try(system(command))

I get the following error:

sh: bedtool..:command not found

Do you think it's a PATH problem?

Thank you!

like image 956
Johnathan Avatar asked Sep 26 '14 17:09

Johnathan


2 Answers

Considered for sure that you 'installed' the command (it exists in a bin somewhere) and after reading yout comment:

if I open RStudio where the function's binaries are located (e.g. open -a RStudio), it works no problem.

I guess that it is a PATH problem indeed. A possible fix would be:

Sys.setenv(PATH=paste(Sys.getenv("PATH"), "/the/bin/folder/of/bedtools", sep=":"))
like image 84
Garini Avatar answered Nov 15 '22 05:11

Garini


Where is your bedtools saved? i.e. what is the output from

which bedtools

If it isn't in your

usr/bin

then the system command gives that error. Save betools there and it should work.

from the system help file it suggests trying the

Sys.which

command on your shell input first to see if it will work in system.

like image 43
mattbawn Avatar answered Nov 15 '22 03:11

mattbawn