diff options
author | Yanbo Liang <ybliang8@gmail.com> | 2015-12-10 10:18:58 -0800 |
---|---|---|
committer | Shivaram Venkataraman <shivaram@cs.berkeley.edu> | 2015-12-10 10:18:58 -0800 |
commit | d9d354ed40eec56b3f03d32f4e2629d367b1bf02 (patch) | |
tree | a567f84f7a6770e7fd4d24c397bb962acf1b3925 | |
parent | 9fba9c8004d2b97549e5456fa7918965bec27336 (diff) | |
download | spark-d9d354ed40eec56b3f03d32f4e2629d367b1bf02.tar.gz spark-d9d354ed40eec56b3f03d32f4e2629d367b1bf02.tar.bz2 spark-d9d354ed40eec56b3f03d32f4e2629d367b1bf02.zip |
[SPARK-12234][SPARKR] Fix ```subset``` function error when only set ```select``` argument
Fix ```subset``` function error when only set ```select``` argument. Please refer to the [JIRA](https://issues.apache.org/jira/browse/SPARK-12234) about the error and how to reproduce it.
cc sun-rui felixcheung shivaram
Author: Yanbo Liang <ybliang8@gmail.com>
Closes #10217 from yanboliang/spark-12234.
-rw-r--r-- | R/pkg/R/DataFrame.R | 9 | ||||
-rw-r--r-- | R/pkg/inst/tests/testthat/test_sparkSQL.R | 4 |
2 files changed, 11 insertions, 2 deletions
diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index 81b4e6b91d..f4c4a2585e 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -1185,7 +1185,7 @@ setMethod("[", signature(x = "DataFrame", i = "Column"), #' #' Return subsets of DataFrame according to given conditions #' @param x A DataFrame -#' @param subset A logical expression to filter on rows +#' @param subset (Optional) A logical expression to filter on rows #' @param select expression for the single Column or a list of columns to select from the DataFrame #' @return A new DataFrame containing only the rows that meet the condition with selected columns #' @export @@ -1206,10 +1206,15 @@ setMethod("[", signature(x = "DataFrame", i = "Column"), #' df[df$age %in% c(19, 30), 1:2] #' subset(df, df$age %in% c(19, 30), 1:2) #' subset(df, df$age %in% c(19), select = c(1,2)) +#' subset(df, select = c(1,2)) #' } setMethod("subset", signature(x = "DataFrame"), function(x, subset, select, ...) { - x[subset, select, ...] + if (missing(subset)) { + x[, select, ...] + } else { + x[subset, select, ...] + } }) #' Select diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R index 222c04a32c..2051784427 100644 --- a/R/pkg/inst/tests/testthat/test_sparkSQL.R +++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R @@ -799,6 +799,10 @@ test_that("subsetting", { expect_equal(count(df6), 1) expect_equal(columns(df6), c("name", "age")) + df7 <- subset(df, select = "name") + expect_equal(count(df7), 3) + expect_equal(columns(df7), c("name")) + # Test base::subset is working expect_equal(nrow(subset(airquality, Temp > 80, select = c(Ozone, Temp))), 68) }) |