I am working on a package that uses RJava for identifier mapping (in biology): BridgeDbR. One of the methods calls a Java method which has vargs, mapID():
xref <- .jnew("org/bridgedb/Xref", identifier, datasource)
datatarget <- getDataSource(code=target)
targets = .jarray(c(datatarget), contents.class="org/bridgedb/DataSource")
Here the getDataSource() method returns a Java object of type org.bridgedb.DataSource.
The actual call of interest is then made like, where (as shown above) xref and targets are Java object, and where mapper is also Java object, see below:
mappings = mapper$mapID(xref, targets)
This mapper object is an instance of the IDMapper interface and defines the mapID() method using vargs:
public Set<Xref> mapID (Xref ref, DataSource... tgtDataSources)
throws IDMapperException;
Now, I want to call this method without data sources. In Java I would just do:
someMapper.mapID(someXref)
... and Java find this method.
However, I cannot figure out how to do this in RJava. The following variants all do not work (e.g. .jarray(c(), contents.class="org/bridgedb/DataSource") return NULL):
mappings = mapper$mapID(xref, c())
mappings = mapper$mapID(xref)
mappings = mapper$mapID(xref, NULL)
mappings = mapper$mapID(xref, .jarray(c(), contents.class="org/bridgedb/DataSource"))
The output of .jmethods(mapper, name="mapID") is:
[1] "public java.util.Set org.bridgedb.rdb.SimpleGdbImplCommon.mapID(org.bridgedb.Xref,org.bridgedb.DataSource[]) throws org.bridgedb.IDMapperException"
[2] "public java.util.Map org.bridgedb.rdb.IDMapperRdb.mapID(java.util.Collection,org.bridgedb.DataSource[]) throws org.bridgedb.IDMapperException"
How can I call this Java method (mapper$mapID) with RJava with just the xref?
As pointed out in https://www.rforge.net/doc/packages/rJava/jarray.html, you should supply a list in the call to .jarray
, possibly with a single NULL
element