Skip to content
Snippets Groups Projects
Commit 8eedf0b5 authored by Sun Rui's avatar Sun Rui Committed by Shivaram Venkataraman
Browse files

[SPARK-13905][SPARKR] Change signature of as.data.frame() to be consistent with the R base package.

## What changes were proposed in this pull request?

Change the signature of as.data.frame() to be consistent with that in the R base package to meet R user's convention.

## How was this patch tested?
dev/lint-r
SparkR unit tests

Author: Sun Rui <rui.sun@intel.com>

Closes #11811 from sun-rui/SPARK-13905.
parent 4514aebd
No related branches found
No related tags found
No related merge requests found
...@@ -2296,12 +2296,8 @@ setMethod("fillna", ...@@ -2296,12 +2296,8 @@ setMethod("fillna",
#' } #' }
setMethod("as.data.frame", setMethod("as.data.frame",
signature(x = "DataFrame"), signature(x = "DataFrame"),
function(x, ...) { function(x, row.names = NULL, optional = FALSE, ...) {
# Check if additional parameters have been passed as.data.frame(collect(x), row.names, optional, ...)
if (length(list(...)) > 0) {
stop(paste("Unused argument(s): ", paste(list(...), collapse = ", ")))
}
collect(x)
}) })
#' The specified DataFrame is attached to the R search path. This means that #' The specified DataFrame is attached to the R search path. This means that
......
...@@ -397,7 +397,10 @@ setGeneric("arrange", function(x, col, ...) { standardGeneric("arrange") }) ...@@ -397,7 +397,10 @@ setGeneric("arrange", function(x, col, ...) { standardGeneric("arrange") })
#' @rdname as.data.frame #' @rdname as.data.frame
#' @export #' @export
setGeneric("as.data.frame") setGeneric("as.data.frame",
function(x, row.names = NULL, optional = FALSE, ...) {
standardGeneric("as.data.frame")
})
#' @rdname attach #' @rdname attach
#' @export #' @export
......
...@@ -26,7 +26,7 @@ test_that("Check masked functions", { ...@@ -26,7 +26,7 @@ test_that("Check masked functions", {
maskedBySparkR <- masked[funcSparkROrEmpty] maskedBySparkR <- masked[funcSparkROrEmpty]
namesOfMasked <- c("describe", "cov", "filter", "lag", "na.omit", "predict", "sd", "var", namesOfMasked <- c("describe", "cov", "filter", "lag", "na.omit", "predict", "sd", "var",
"colnames", "colnames<-", "intersect", "rank", "rbind", "sample", "subset", "colnames", "colnames<-", "intersect", "rank", "rbind", "sample", "subset",
"summary", "transform", "drop", "window") "summary", "transform", "drop", "window", "as.data.frame")
expect_equal(length(maskedBySparkR), length(namesOfMasked)) expect_equal(length(maskedBySparkR), length(namesOfMasked))
expect_equal(sort(maskedBySparkR), sort(namesOfMasked)) expect_equal(sort(maskedBySparkR), sort(namesOfMasked))
# above are those reported as masked when `library(SparkR)` # above are those reported as masked when `library(SparkR)`
......
...@@ -1863,6 +1863,9 @@ test_that("Method as.data.frame as a synonym for collect()", { ...@@ -1863,6 +1863,9 @@ test_that("Method as.data.frame as a synonym for collect()", {
expect_equal(as.data.frame(irisDF), collect(irisDF)) expect_equal(as.data.frame(irisDF), collect(irisDF))
irisDF2 <- irisDF[irisDF$Species == "setosa", ] irisDF2 <- irisDF[irisDF$Species == "setosa", ]
expect_equal(as.data.frame(irisDF2), collect(irisDF2)) expect_equal(as.data.frame(irisDF2), collect(irisDF2))
# Make sure as.data.frame in the R base package is not covered
expect_that(as.data.frame(c(1, 2)), not(throws_error()))
}) })
test_that("attach() on a DataFrame", { test_that("attach() on a DataFrame", {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment