Johnathan
Johnathan

Reputation: 1917

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

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!

Upvotes: 9

Views: 4539

Answers (2)

Garini
Garini

Reputation: 1204

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=":"))

Upvotes: 5

mattbawn
mattbawn

Reputation: 1378

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.

Upvotes: 1

Related Questions