From e3ae104dc1ee47c359b25c21ba56c96022a17558 Mon Sep 17 00:00:00 2001 From: felixcheung Date: Fri, 21 Aug 2015 10:10:14 -0700 Subject: [PATCH] [SPARK-9317] [SPARKR] Change `show` to print DataFrame entries --- R/pkg/R/DataFrame.R | 9 +++------ R/pkg/inst/tests/test_sparkSQL.R | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index 895603235011e..e025be29e73fd 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -176,9 +176,10 @@ setMethod("showDF", #' show #' -#' Print the DataFrame column names and types +#' Print the first numRows rows of a DataFrame #' #' @param x A SparkSQL DataFrame +#' Defaults to print 20 rows. #' #' @rdname show #' @export @@ -192,11 +193,7 @@ setMethod("showDF", #'} setMethod("show", "DataFrame", function(object) { - cols <- lapply(dtypes(object), function(l) { - paste(l, collapse = ":") - }) - s <- paste(cols, collapse = ", ") - cat(paste("DataFrame[", s, "]\n", sep = "")) + showDF(object) }) #' DataTypes diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R index 556b8c5447054..e18826088ede3 100644 --- a/R/pkg/inst/tests/test_sparkSQL.R +++ b/R/pkg/inst/tests/test_sparkSQL.R @@ -953,6 +953,28 @@ test_that("showDF()", { expect_output(s , expected) }) +test_that("show()", { + df <- jsonFile(sqlContext, jsonPath) + s <- capture.output(df) + expected <- paste("+----+-------+\n", + "| age| name|\n", + "+----+-------+\n", + "|null|Michael|\n", + "| 30| Andy|\n", + "| 19| Justin|\n", + "+----+-------+\n", sep="") + expect_output(s , expected) + s1 <- capture.output(show(df)) + expected1 <- paste("+----+-------+\n", + "| age| name|\n", + "+----+-------+\n", + "|null|Michael|\n", + "| 30| Andy|\n", + "| 19| Justin|\n", + "+----+-------+\n", sep="") + expect_output(s1 , expected1) +}) + test_that("isLocal()", { df <- jsonFile(sqlContext, jsonPath) expect_false(isLocal(df))