pogibas
pogibas

Reputation: 28379

R: OS command invoked by "system" can't find library

I am using program bedtools and it works perfectly when I am invoking it from my OS (CentOS release 6.4). I tried to invoke this program using R system and it gave me error:

bedtools: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by bedtools)

My R version is: 3.0.1 (2013-05-16) -- "Good Sport"

How can I solve this problem?

Upvotes: 2

Views: 296

Answers (1)

Backlin
Backlin

Reputation: 14872

The reason for not being able to run bedtools from within R is that the shell environment is different from the environment outside R. This is a suggestion for how to track down the difference, but since I don't have access to the actual computer it contains a fair amount of guesswork.

It appears that there are multiple versions of libstdc++ (needed to run bedtools) on your system. Run the following command to see which ones you have:

$ locate libstdc++.so

/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libstdc++.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/32/libstdc++.so
/usr/lib64/libstdc++.so.6
/usr/lib64/libstdc++.so.6.0.13

Then run the following command on them to see if they differ in versions

$ strings /usr/lib64/libstdc++.so.6 | grep GLIBC

GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBC_2.2.5
GLIBC_2.3
GLIBC_2.4
GLIBC_2.3.2
GLIBCXX_FORCE_NEW
GLIBCXX_DEBUG_MESSAGE_LENGTH

If you find GLIBCXX_3.4.15 in one of them, search for its directory among the environment variables outside R to see which it belongs to:

$ set | grep "<path>"

When you find the right environment variable, add the path to it inside R with Sys.setenv as suggested by @morispaa.

Sys.setenv(<VARIABLE> = paste0("<path>:", Sys.getenv("<VARIABLE>"))

Best of luck!

Original answer:

I suspect that you set some environment variable in you .bashrc or similar that points out the library, perhaps you add it to your $PATH?

As a matter of fact, system exectues statements you give it in new shell session, in which your .bashrc and similar config files are not sourced. As an example, I set the variable HISTSIZE=1000 in my .bashrc and I can view it in bash by typing:

~$ echo $HISTSIZE
1000

But if I do the same thing in R I get nothing

> system("echo $HISTSIZE")

On the other hand, if I set it and before echoing it I do get it back (obviously)

> system("export HISTSIZE=1000 && echo $HISTSIZE")
1000

but after the system call is completed it is no longer there if I do another

> system("echo $HISTSIZE")

Upvotes: 2

Related Questions