| <!DOCTYPE html> |
| <!-- Generated by pkgdown: do not edit by hand --><html lang="en"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
| <meta name="description" content="Provides an R Front end for Apache Spark <https://spark.apache.org>."> |
| <!-- Inform modern browsers that this page supports both dark and light color schemes, |
| and the page author prefers light. --><meta name="color-scheme" content="dark light"> |
| <script> |
| // If `prefers-color-scheme` is not supported, fall back to light mode. |
| // i.e. In this case, inject the `light` CSS before the others, with |
| // no media filter so that it will be downloaded with highest priority. |
| if (window.matchMedia("(prefers-color-scheme: dark)").media === "not all") { |
| document.documentElement.style.display = "none"; |
| document.head.insertAdjacentHTML( |
| "beforeend", |
| "<link id=\"css\" rel=\"stylesheet\" href=\"https://bootswatch.com/5/flatly/bootstrap.css\" onload=\"document.documentElement.style.display = ''\">" |
| ); |
| } |
| </script><title>R Front End for Apache Spark • SparkR</title> |
| <script src="deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
| <link href="deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet"> |
| <script src="deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="deps/font-awesome-6.5.2/css/all.min.css" rel="stylesheet"> |
| <link href="deps/font-awesome-6.5.2/css/v4-shims.min.css" rel="stylesheet"> |
| <script src="deps/headroom-0.11.0/headroom.min.js"></script><script src="deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="deps/search-1.0.0/fuse.min.js"></script><script src="deps/search-1.0.0/mark.min.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous"> |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous"> |
| <!-- bootstrap-toc --><script src="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.js"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="pkgdown.js"></script><link href="extra.css" rel="stylesheet"> |
| <meta property="og:title" content="R Front End for Apache Spark"> |
| <meta property="og:description" content="Provides an R Front end for Apache Spark <https://spark.apache.org>."> |
| <!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]> |
| <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> |
| <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> |
| <![endif]--><!-- Flatly Theme - Light --><link id="css-light" rel="stylesheet" href="https://bootswatch.com/5/flatly/bootstrap.css" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"> |
| <!-- Darkly Theme - Dark --><link id="css-dark" rel="stylesheet" href="https://bootswatch.com/5/darkly/bootstrap.css" media="(prefers-color-scheme: dark)"> |
| <!-- preferably CSS --><link rel="stylesheet" href="preferably.css"> |
| <link id="css-code-light" rel="stylesheet" href="code-color-scheme-light.css" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)"> |
| <link id="css-code-dark" rel="stylesheet" href="code-color-scheme-dark.css" media="(prefers-color-scheme: dark)"> |
| <script src="darkswitch.js"></script> |
| </head> |
| <body> |
| <a href="#main" class="visually-hidden-focusable">Skip to contents</a> |
| |
| |
| <nav class="navbar fixed-top navbar-dark navbar-expand-lg bg-primary"><div class="container"> |
| <a class="external-link navbar-brand" href="https://spark.apache.org/"> |
| <img src="https://spark.apache.org/images/spark-logo-rev.svg" alt="" max-height="100%"></a> |
| |
| <a class="navbar-brand me-2" href="index.html">SparkR</a> |
| |
| <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">3.5.4</small> |
| |
| |
| <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation"> |
| <span class="navbar-toggler-icon"></span> |
| </button> |
| |
| <div id="navbar" class="collapse navbar-collapse ms-2"> |
| <ul class="navbar-nav me-auto"> |
| <li class="nav-item"><a class="nav-link" href="reference/index.html">Reference</a></li> |
| <li class="nav-item dropdown"> |
| <button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true">Articles</button> |
| <ul class="dropdown-menu" aria-labelledby="dropdown-articles"> |
| <li><a class="dropdown-item" href="articles/sparkr-vignettes.html">SparkR - Practical Guide</a></li> |
| </ul> |
| </li> |
| </ul> |
| <form class="form-inline my-2 my-lg-0" role="search"> |
| <input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="search.json" id="search-input" placeholder="" autocomplete="off"> |
| </form> |
| |
| <ul class="navbar-nav"> |
| <li class="nav-item"><form class="form-inline" role="search"> |
| <input class="form-control" type="search" name="search-input" id="search-input" autocomplete="off" aria-label="Search site" placeholder="Search for" data-search-index="search.json"> |
| </form></li> |
| |
| |
| <li> |
| <a class="external-link nav-link" id="css-toggle-btn" aria-label="github"> |
| <span class="fas fa fas fa-adjust fa-lg"></span> |
| </a> |
| </li> |
| |
| |
| |
| </ul> |
| </div> |
| |
| |
| </div> |
| </nav><div class="container template-home"> |
| <div class="row"> |
| <main id="main" class="col-md-9"><div class="section level1"> |
| <div class="page-header"><h1 id="r-on-spark">R on Spark<a class="anchor" aria-label="anchor" href="#r-on-spark"></a> |
| </h1></div> |
| <p>SparkR is an R package that provides a light-weight frontend to use Spark from R.</p> |
| <div class="section level3"> |
| <h3 id="installing-sparkr">Installing sparkR<a class="anchor" aria-label="anchor" href="#installing-sparkr"></a> |
| </h3> |
| <p>Libraries of sparkR need to be created in <code>$SPARK_HOME/R/lib</code>. This can be done by running the script <code>$SPARK_HOME/R/install-dev.sh</code>. By default the above script uses the system wide installation of R. However, this can be changed to any user installed location of R by setting the environment variable <code>R_HOME</code> the full path of the base directory where R is installed, before running install-dev.sh script. Example:</p> |
| <div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb1-1" title="1"><span class="co"># where /home/username/R is where R is installed and /home/username/R/bin contains the files R and RScript</span></a> |
| <a class="sourceLine" id="cb1-2" title="2"><span class="bu">export</span> <span class="va">R_HOME=</span>/home/username/R</a> |
| <a class="sourceLine" id="cb1-3" title="3"><span class="ex">./install-dev.sh</span></a></code></pre></div> |
| </div> |
| <div class="section level3"> |
| <h3 id="sparkr-development">SparkR development<a class="anchor" aria-label="anchor" href="#sparkr-development"></a> |
| </h3> |
| <div class="section level4"> |
| <h4 id="build-spark">Build Spark<a class="anchor" aria-label="anchor" href="#build-spark"></a> |
| </h4> |
| <p>Build Spark with <a href="https://spark.apache.org/docs/latest/building-spark.html#buildmvn" class="external-link">Maven</a> or <a href="https://spark.apache.org/docs/latest/building-spark.html#building-with-sbt" class="external-link">SBT</a>, and include the <code>-Psparkr</code> profile to build the R package. For example to use the default Hadoop versions you can run</p> |
| <div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb2-1" title="1"><span class="co"># Maven</span></a> |
| <a class="sourceLine" id="cb2-2" title="2"><span class="ex">./build/mvn</span> -DskipTests -Psparkr package</a> |
| <a class="sourceLine" id="cb2-3" title="3"></a> |
| <a class="sourceLine" id="cb2-4" title="4"><span class="co"># SBT</span></a> |
| <a class="sourceLine" id="cb2-5" title="5"><span class="ex">./build/sbt</span> -Psparkr package</a></code></pre></div> |
| </div> |
| <div class="section level4"> |
| <h4 id="running-sparkr">Running sparkR<a class="anchor" aria-label="anchor" href="#running-sparkr"></a> |
| </h4> |
| <p>You can start using SparkR by launching the SparkR shell with</p> |
| <div class="sourceCode" id="cb3"><pre class="sourceCode R"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" title="1">.<span class="op">/</span>bin<span class="op">/</span>sparkR</a></code></pre></div> |
| <p>The <code>sparkR</code> script automatically creates a SparkContext with Spark by default in local mode. To specify the Spark master of a cluster for the automatically created SparkContext, you can run</p> |
| <div class="sourceCode" id="cb4"><pre class="sourceCode R"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" title="1">.<span class="op">/</span>bin<span class="op">/</span>sparkR <span class="op">--</span>master <span class="st">"local[2]"</span></a></code></pre></div> |
| <p>To set other options like driver memory, executor memory etc. you can pass in the <a href="https://spark.apache.org/docs/latest/submitting-applications.html" class="external-link">spark-submit</a> arguments to <code>./bin/sparkR</code></p> |
| </div> |
| <div class="section level4"> |
| <h4 id="using-sparkr-from-rstudio">Using SparkR from RStudio<a class="anchor" aria-label="anchor" href="#using-sparkr-from-rstudio"></a> |
| </h4> |
| <p>If you wish to use SparkR from RStudio, please refer <a href="https://spark.apache.org/docs/latest/sparkr.html#starting-up-from-rstudio" class="external-link">SparkR documentation</a>.</p> |
| </div> |
| <div class="section level4"> |
| <h4 id="making-changes-to-sparkr">Making changes to SparkR<a class="anchor" aria-label="anchor" href="#making-changes-to-sparkr"></a> |
| </h4> |
| <p>The <a href="https://spark.apache.org/contributing.html" class="external-link">instructions</a> for making contributions to Spark also apply to SparkR. If you only make R file changes (i.e. no Scala changes) then you can just re-install the R package using <code>R/install-dev.sh</code> and test your changes. Once you have made your changes, please include unit tests for them and run existing unit tests using the <code>R/run-tests.sh</code> script as described below.</p> |
| </div> |
| <div class="section level4"> |
| <h4 id="generating-documentation">Generating documentation<a class="anchor" aria-label="anchor" href="#generating-documentation"></a> |
| </h4> |
| <p>The SparkR documentation (Rd files and HTML files) are not a part of the source repository. To generate them you can run the script <code>R/create-docs.sh</code>. This script uses <code>devtools</code> and <code>knitr</code> to generate the docs and these packages need to be installed on the machine before using the script. Also, you may need to install these <a href="https://github.com/apache/spark/tree/master/docs#prerequisites" class="external-link">prerequisites</a>. See also, <code>R/DOCUMENTATION.md</code></p> |
| </div> |
| </div> |
| <div class="section level3"> |
| <h3 id="examples-unit-tests">Examples, Unit tests<a class="anchor" aria-label="anchor" href="#examples-unit-tests"></a> |
| </h3> |
| <p>SparkR comes with several sample programs in the <code>examples/src/main/r</code> directory. To run one of them, use <code>./bin/spark-submit <filename> <args></code>. For example:</p> |
| <div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb5-1" title="1"><span class="ex">./bin/spark-submit</span> examples/src/main/r/dataframe.R</a></code></pre></div> |
| <p>You can run R unit tests by following the instructions under <a href="https://spark.apache.org/docs/latest/building-spark.html#running-r-tests" class="external-link">Running R Tests</a>.</p> |
| </div> |
| <div class="section level3"> |
| <h3 id="running-on-yarn">Running on YARN<a class="anchor" aria-label="anchor" href="#running-on-yarn"></a> |
| </h3> |
| <p>The <code>./bin/spark-submit</code> can also be used to submit jobs to YARN clusters. You will need to set YARN conf dir before doing so. For example on CDH you can run</p> |
| <div class="sourceCode" id="cb6"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb6-1" title="1"><span class="bu">export</span> <span class="va">YARN_CONF_DIR=</span>/etc/hadoop/conf</a> |
| <a class="sourceLine" id="cb6-2" title="2"><span class="ex">./bin/spark-submit</span> --master yarn examples/src/main/r/dataframe.R</a></code></pre></div> |
| </div> |
| </div> |
| </main><aside class="col-md-3"><div class="links"> |
| <h2 data-toc-skip>Links</h2> |
| <ul class="list-unstyled"> |
| <li><a href="https://cloud.r-project.org/package=SparkR" class="external-link">View on CRAN</a></li> |
| <li><a href="https://spark.apache.org/contributing.html" class="external-link">Report a bug</a></li> |
| </ul> |
| </div> |
| |
| <div class="license"> |
| <h2 data-toc-skip>License</h2> |
| <ul class="list-unstyled"> |
| <li>Apache License (== 2.0)</li> |
| </ul> |
| </div> |
| |
| |
| <div class="citation"> |
| <h2 data-toc-skip>Citation</h2> |
| <ul class="list-unstyled"> |
| <li><a href="authors.html#citation">Citing SparkR</a></li> |
| </ul> |
| </div> |
| |
| <div class="developers"> |
| <h2 data-toc-skip>Developers</h2> |
| <ul class="list-unstyled"> |
| <li> |
| <a href="https://www.apache.org/" class="external-link"> The Apache Software Foundation</a> <br><small class="roles"> Author, maintainer, copyright holder </small> </li> |
| </ul> |
| </div> |
| |
| |
| |
| </aside> |
| </div> |
| |
| |
| <footer><div class="copyright"> |
| <p></p> |
| <p>Developed by <a href="https://www.apache.org/" class="external-link"> The Apache Software Foundation</a>.</p> |
| </div> |
| |
| <div class="pkgdown"> |
| <p></p> |
| <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.1.</p> |
| <p class="preferably">Using <a href="https://preferably.amirmasoudabdol.name/?source=footer" class="external-link">preferably</a> template.</p> |
| </div> |
| |
| </footer> |
| </div> |
| |
| |
| |
| |
| |
| </body> |
| </html> |