MyNixOS website logo
Description

Interface for 'GraphFrames'.

A 'sparklyr' <https://spark.rstudio.com/> extension that provides an R interface for 'GraphFrames' <https://graphframes.github.io/>. 'GraphFrames' is a package for 'Apache Spark' that provides a DataFrame-based API for working with graphs. Functionality includes motif finding and common graph algorithms, such as PageRank and Breadth-first search.

R interface for GraphFrames

BuildStatus Coveragestatus CRANstatus

Installation

For those already using sparklyr simply run:

install.packages("graphframes")
# or, for the development version,
# devtools::install_github("rstudio/graphframes")

Otherwise, install first sparklyr from CRAN using:

install.packages("sparklyr")

The examples make use of the highschool dataset from the ggplot package.

Getting Started

We will calculate PageRank over the built-in “friends” dataset as follows.

library(graphframes)
library(sparklyr)
library(dplyr)

# connect to spark using sparklyr
sc <- spark_connect(master = "local", version = "2.3.0")

# obtain the example graph
g <- gf_friends(sc)

# compute PageRank
results <- gf_pagerank(g, tol = 0.01, reset_probability = 0.15)
results
## GraphFrame
## Vertices:
##   $ id       <chr> "f", "b", "g", "a", "d", "c", "e"
##   $ name     <chr> "Fanny", "Bob", "Gabby", "Alice", "David", "Charlie",...
##   $ age      <int> 36, 36, 60, 34, 29, 30, 32
##   $ pagerank <dbl> 0.3283607, 2.6555078, 0.1799821, 0.4491063, 0.3283607...
## Edges:
##   $ src          <chr> "b", "c", "d", "e", "a", "a", "e", "f"
##   $ dst          <chr> "c", "b", "a", "f", "e", "b", "d", "c"
##   $ relationship <chr> "follow", "follow", "friend", "follow", "friend",...
##   $ weight       <dbl> 1.0, 1.0, 1.0, 0.5, 0.5, 0.5, 0.5, 1.0

We can then visualize the results by collecting the results to R:

library(tidygraph)
library(ggraph)

vertices <- results %>%
  gf_vertices() %>%
  collect()

edges <- results %>%
  gf_edges() %>%
  collect()

edges %>%
  as_tbl_graph() %>%
  activate(nodes) %>%
  left_join(vertices, by = c(name = "id")) %>%
  ggraph(layout = "nicely") +
  geom_node_label(aes(label = name.y, color = pagerank)) +
  geom_edge_link(
    aes(
      alpha = weight,
      start_cap = label_rect(node1.name.y),
      end_cap = label_rect(node2.name.y)
    ),
    arrow = arrow(length = unit(4, "mm"))
  ) +
  theme_graph(fg_text_colour = 'white')

Further Reading

Appart from calculating PageRank using gf_pagerank, many other functions are available, including:

  • gf_bfs(): Breadth-first search (BFS).
  • gf_connected_components(): Connected components.
  • gf_shortest_paths(): Shortest paths algorithm.
  • gf_scc(): Strongly connected components.
  • gf_triangle_count(): Computes the number of triangles passing through each vertex and others.
  • gf_degrees(): Degrees of vertices

For instance, one can calculate the degrees of vertices using gf_degrees as follows:

gf_friends(sc) %>% gf_degrees()
## # Source: spark<?> [?? x 2]
##   id    degree
## * <chr>  <int>
## 1 f          2
## 2 b          3
## 3 a          3
## 4 c          3
## 5 e          3
## 6 d          2

Finally, we disconnect from Spark:

spark_disconnect(sc)
Metadata

Version

0.1.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows