在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
InstallationYou can install the sparklyr package from CRAN as follows:
You should also install a local version of Spark for development purposes:
To upgrade to the latest version of sparklyr, run the following command and restart your r session:
If you use the RStudio IDE, you should also download the latest preview release of the IDE which includes several enhancements for interacting with Spark (see the RStudio IDE section below for more details). Connecting to SparkYou can connect to both local instances of Spark as well as remote Spark clusters. Here we<u+2019>ll connect to a local instance of Spark via the spark_connect function:
The returned Spark connection ( For more information on connecting to remote Spark clusters see the Deployment section of the sparklyr website. Using dplyrWe can new use all of the available dplyr verbs against the tables within the cluster. We<u+2019>ll start by copying some datasets from R into the Spark cluster (note that you may need to install the nycflights13 and Lahman packages in order to execute this code):
To start with here<u+2019>s a simple filtering example:
Introduction to dplyr provides additional dplyr examples you can try. For example, consider the last example from the tutorial which plots data on flight delays:
Window Functionsdplyr window functions are also supported, for example:
For additional documentation on using dplyr with Spark see the dplyr section of the sparklyr website. Using SQLIt<u+2019>s also possible to execute SQL queries directly against tables within a Spark cluster. The
Machine LearningYou can orchestrate machine learning algorithms in a Spark cluster via the machine learning functions within sparklyr. These functions connect to a set of high-level APIs built on top of DataFrames that help you create and tune machine learning workflows. Here<u+2019>s an example where we use ml_linear_regression to fit a linear regression model. We<u+2019>ll use the built-in
For linear regression models produced by Spark, we can use
Spark machine learning supports a wide array of algorithms and feature transformations and as illustrated above it<u+2019>s easy to chain these functions together with dplyr pipelines. To learn more see the machine learning section. Reading and Writing DataYou can read and write data in CSV, JSON, and Parquet formats. Data can be stored in HDFS, S3, or on the local filesystem of cluster nodes.
ExtensionsThe facilities used internally by sparklyr for its dplyr and machine learning interfaces are available to extension packages. Since Spark is a general purpose cluster computing system there are many potential applications for extensions (e.g.<u+00a0>interfaces to custom machine learning pipelines, interfaces to 3rd party Spark packages, etc.). Here<u+2019>s a simple example that wraps a Spark text file line counting function with an R function:
To learn more about creating extensions see the Extensions section of the sparklyr website. Table UtilitiesYou can cache a table into memory with:
and unload from memory using:
Connection UtilitiesYou can view the Spark web console using the
You can show the log using the
Finally, we disconnect from Spark:
RStudio IDEThe latest RStudio Preview Release of the RStudio IDE includes integrated support for Spark and the sparklyr package, including tools for:
Once you<u+2019>ve installed the sparklyr package, you should find a new Spark pane within the IDE. This pane includes a New Connection dialog which can be used to make connections to local or remote Spark instances: Once you<u+2019>ve connected to Spark you<u+2019>ll be able to browse the tables contained within the Spark cluster: The Spark DataFrame preview uses the standard RStudio data viewer: The RStudio IDE features for sparklyr are available now as part of the RStudio Preview Release. Using H2Orsparkling is a CRAN package from H2O that extends sparklyr to provide an interface into Sparkling Water. For instance, the following example installs, configures and runs h2o.glm:
Connecting through LivyLivy enables remote connections to Apache Spark clusters. Connecting to Spark clusters through Livy is under experimental development in Before connecting to Livy, you will need the connection information to an existing service running Livy. Otherwise, to test To connect, use the Livy service address as
Once you are done using To connect to remote
Links
LicenseApache License 2.0 | file LICENSE Developers
Developed by Javier Luraschi, Kevin Ushey, JJ Allaire, The Apache Software Foundation. Site built with pkgdown.
参考 http://spark.rstudio.com/ http://alitrack.com/2016/11/01/sparklyr-r%E8%AF%AD%E8%A8%80%E8%AE%BF%E9%97%AEspark%E7%9A%84%E5%8F%A6%E5%A4%96%E4%B8%80%E7%A7%8D%E6%96%B9%E6%B3%95/ |
请发表评论