Skip to content

Commit c4e19b3

Browse files
committed
[SPARK-11587][SPARKR] Fix the summary generic to match base R
The signature is summary(object, ...) as defined in https://stat.ethz.ch/R-manual/R-devel/library/base/html/summary.html Author: Shivaram Venkataraman <[email protected]> Closes #9582 from shivaram/summary-fix.
1 parent 1431319 commit c4e19b3

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

R/pkg/R/DataFrame.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,9 +1944,9 @@ setMethod("describe",
19441944
#' @rdname summary
19451945
#' @name summary
19461946
setMethod("summary",
1947-
signature(x = "DataFrame"),
1948-
function(x) {
1949-
describe(x)
1947+
signature(object = "DataFrame"),
1948+
function(object, ...) {
1949+
describe(object)
19501950
})
19511951

19521952

R/pkg/R/generics.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ setGeneric("summarize", function(x,...) { standardGeneric("summarize") })
561561

562562
#' @rdname summary
563563
#' @export
564-
setGeneric("summary", function(x, ...) { standardGeneric("summary") })
564+
setGeneric("summary", function(object, ...) { standardGeneric("summary") })
565565

566566
# @rdname tojson
567567
# @export

R/pkg/R/mllib.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ setMethod("predict", signature(object = "PipelineModel"),
8989
#' model <- glm(y ~ x, trainingData)
9090
#' summary(model)
9191
#'}
92-
setMethod("summary", signature(x = "PipelineModel"),
93-
function(x, ...) {
92+
setMethod("summary", signature(object = "PipelineModel"),
93+
function(object, ...) {
9494
modelName <- callJStatic("org.apache.spark.ml.api.r.SparkRWrappers",
95-
"getModelName", x@model)
95+
"getModelName", object@model)
9696
features <- callJStatic("org.apache.spark.ml.api.r.SparkRWrappers",
97-
"getModelFeatures", x@model)
97+
"getModelFeatures", object@model)
9898
coefficients <- callJStatic("org.apache.spark.ml.api.r.SparkRWrappers",
99-
"getModelCoefficients", x@model)
99+
"getModelCoefficients", object@model)
100100
if (modelName == "LinearRegressionModel") {
101101
devianceResiduals <- callJStatic("org.apache.spark.ml.api.r.SparkRWrappers",
102-
"getModelDevianceResiduals", x@model)
102+
"getModelDevianceResiduals", object@model)
103103
devianceResiduals <- matrix(devianceResiduals, nrow = 1)
104104
colnames(devianceResiduals) <- c("Min", "Max")
105105
rownames(devianceResiduals) <- rep("", times = 1)

R/pkg/inst/tests/test_mllib.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,9 @@ test_that("summary coefficients match with native glm of family 'binomial'", {
113113
rownames(stats$Coefficients) ==
114114
c("(Intercept)", "Sepal_Length", "Sepal_Width")))
115115
})
116+
117+
test_that("summary works on base GLM models", {
118+
baseModel <- stats::glm(Sepal.Width ~ Sepal.Length + Species, data = iris)
119+
baseSummary <- summary(baseModel)
120+
expect_true(abs(baseSummary$deviance - 12.19313) < 1e-4)
121+
})

0 commit comments

Comments
 (0)