I would like to make use of open babel from within the R language.
Initially I just need to do some format conversions, but may expand the
usage to other parts of OpenBabel as well. I am familiar with embedding
C/C++ code in R, but I'm having some trouble with the plugin mechanism
of OpenBabel in this case. The problem is that the formats are not
available when I run the OpenBabel code from within R. So, for example,
if I search for the SDF format like so:
OBFormat *format = conv.FindFormat("SDF");
I always get back a 0 value. The same chunk of code executed outside of
R, as a normal stand-alone program, works fine. So does anyone know how
I can ensure that the formats get loaded? Thanks.
One other thing to mention, someone might suggest linking against a
static version of openbabel which includes all the plugins. I would like
to avoid that if possible since this needs to work in an R package that
will be distributed across platforms, so it would be hard to ask people
to compile a special, static, version of openbabel just to compile this
R package. Since it needs to work on windows, mac and linux, it would be
nice if I can make use of any existing installed shared obenbabel
libraries. If it turns out it can't be done, then I'll go down that
path. Thanks.
Here is an example of the problem:
test program (obtest2.cc):
#include <iostream>
#include <openbabel/obconversion.h>
#include <R.h>
#include <Rinternals.h>
extern "C" { SEXP test(); }
int main(){
test();
}
SEXP test()
{
OpenBabel::OBConversion conv;
OpenBabel::OBFormat *format = conv.FindFormat("SDF"); //
search for SDF format
std::cout<<"format: "<<format<<std::endl;
// print out search result, either 0
// or an address
return R_NilValue;
}
compile:
g++ -I/usr/include/openbabel-2.0 -I/usr/share/R/include -fpic -c
obtest2.cc -o obtest2.o
g++ -o obtest2 obtest2.o -fpic -lopenbabel
-lR # Executable
g++ -shared -o libobtest2.so obtest2.o -fpic -lopenbabel -lR # R
library
Run executable:
$ ./obtest2
format: 0x7f1858275d20 #found some result, this is what I expect
Run in R:
R>dyn.load("libobtest2.so")
R>.Call("test")
format: 0 # the format was not found, so 0 was
returned
NULL
Kevin
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
OpenBabel-Devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbabel-devel