title: How to run SparkR script using spark-submit or sparkR on an EMR cluster?
body: <p>I have written a sparkR code and wondering if I can submit it using spark-submit or sparkR on an EMR cluster.</p>
  
  <p>I have tried several ways for example:
  sparkR mySparkRScript.r or sparkR --no-save mySparkScript.r etc.. but every time I am getting below error:</p>
  
  <pre><code>Error in sparkR.sparkContext(master, appName, sparkHome, sparkConfigMap,  : 
  JVM is not ready after 10 seconds
  </code></pre>
  
  <p>Sample Code:</p>
  
  <pre><code>#Set the path for the R libraries you would like to use.
  #You may need to modify this if you have custom R libraries.
  .libPaths(c(.libPaths(), '/usr/lib/spark/R/lib'))
  
  #Set the SPARK_HOME environment variable to the location on EMR
  Sys.setenv(SPARK_HOME = '/usr/lib/spark')
  
  #Load the SparkR library into R
  library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R", "lib")))
  
  #Initiate a Spark context and identify where the master node is located.
  #local is used here because the RStudio server
  #was installed on the master node
  
  sc &lt;- sparkR.session(master = "local[*]", sparkEnvir = list(spark.driver.memory="2g"))
  
  sqlContext &lt;- sparkRSQL.init(sc)
  </code></pre>
  
  <p>Note: I am able to run my code in sparkr-shell by pasting directly or using <a href="https://stackoverflow.com/a/39624829/5234626">source("mySparkRScript.R")</a>.</p>
  
  <p>Ref: </p>
  
  <ol>
  <li><a href="https://aws.amazon.com/blogs/big-data/crunching-statistics-at-scale-with-sparkr-on-amazon-emr/" rel="nofollow noreferrer">Crunching Statistics at Scale with SparkR on Amazon EMR</a></li>
  <li><a href="https://spark.apache.org/docs/latest/sparkr.html" rel="nofollow noreferrer">SparkR Spark documentation</a></li>
  <li><a href="https://amplab-extras.github.io/SparkR-pkg/" rel="nofollow noreferrer">R on Spark</a></li>
  <li><a href="https://www.linkedin.com/pulse/executing-existing-r-scripts-from-spark-rutger-de-graaf/" rel="nofollow noreferrer">Executing-existing-r-scripts-from-spark-rutger-de-graaf</a></li>
  <li><a href="https://github.com/apache/spark/tree/master/R" rel="nofollow noreferrer">Github</a></li>
  </ol>