blob: 8d2e9ca814be6298a037fdce12bcb821da20b711 [file] [log] [blame]
<!DOCTYPE html><html><head><title>R: Call Java Methods</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.css">
<script type="text/javascript">
const macros = { "\\R": "\\textsf{R}", "\\code": "\\texttt"};
function processMathHTML() {
var l = document.getElementsByClassName('reqn');
for (let e of l) { katex.render(e.textContent, e, { throwOnError: false, macros }); }
return;
}</script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.15.3/dist/katex.min.js"
onload="processMathHTML();"></script>
<link rel="stylesheet" type="text/css" href="R.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/styles/github.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.3/languages/r.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head><body><div class="container">
<table style="width: 100%;"><tr><td>sparkR.callJMethod {SparkR}</td><td style="text-align: right;">R Documentation</td></tr></table>
<h2>Call Java Methods</h2>
<h3>Description</h3>
<p>Call a Java method in the JVM running the Spark driver. The return
values are automatically converted to R objects for simple objects. Other
values are returned as &quot;jobj&quot; which are references to objects on JVM.
</p>
<h3>Usage</h3>
<pre><code class='language-R'>sparkR.callJMethod(x, methodName, ...)
</code></pre>
<h3>Arguments</h3>
<table>
<tr style="vertical-align: top;"><td><code>x</code></td>
<td>
<p>object to invoke the method on. Should be a &quot;jobj&quot; created by newJObject.</p>
</td></tr>
<tr style="vertical-align: top;"><td><code>methodName</code></td>
<td>
<p>method name to call.</p>
</td></tr>
<tr style="vertical-align: top;"><td><code>...</code></td>
<td>
<p>parameters to pass to the Java method.</p>
</td></tr>
</table>
<h3>Details</h3>
<p>This is a low level function to access the JVM directly and should only be used
for advanced use cases. The arguments and return values that are primitive R
types (like integer, numeric, character, lists) are automatically translated to/from
Java types (like Integer, Double, String, Array). A full list can be found in
serialize.R and deserialize.R in the Apache Spark code base.
</p>
<h3>Value</h3>
<p>the return value of the Java method. Either returned as a R object
if it can be deserialized or returned as a &quot;jobj&quot;. See details section for more.
</p>
<h3>Note</h3>
<p>sparkR.callJMethod since 2.0.1
</p>
<h3>See Also</h3>
<p><a href="../../SparkR/help/sparkR.callJStatic.html">sparkR.callJStatic</a>, <a href="../../SparkR/help/sparkR.newJObject.html">sparkR.newJObject</a>
</p>
<h3>Examples</h3>
<pre><code class="r">## Not run:
##D sparkR.session() # Need to have a Spark JVM running before calling newJObject
##D # Create a Java ArrayList and populate it
##D jarray &lt;- sparkR.newJObject(&quot;java.util.ArrayList&quot;)
##D sparkR.callJMethod(jarray, &quot;add&quot;, 42L)
##D sparkR.callJMethod(jarray, &quot;get&quot;, 0L) # Will print 42
## End(Not run)
</code></pre>
<hr /><div style="text-align: center;">[Package <em>SparkR</em> version 3.2.2 <a href="00Index.html">Index</a>]</div>
</div>
</body></html>