# NOT RUN {
library(sparklyr)
sc <- spark_connect(master = "local[3]")
# copy some test data into a Spark Dataframe
sdf <- sdf_copy_to(sc, iris, overwrite = TRUE)
# create a writer function
writer <- function(df, path) {
  write.csv(df, path)
}
spark_write(
  sdf,
  writer,
  # re-partition sdf into 3 partitions and write them to 3 separate files
  paths = list("file:///tmp/file1", "file:///tmp/file2", "file:///tmp/file3"),
)
spark_write(
  sdf,
  writer,
  # save all rows into a single file
  paths = list("file:///tmp/all_rows")
)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab