aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
Diffstat (limited to 'R')
-rw-r--r--R/pkg/R/DataFrame.R8
-rw-r--r--R/pkg/inst/tests/test_sparkSQL.R5
2 files changed, 12 insertions, 1 deletions
diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R
index 861fe1c78b..b59b700af5 100644
--- a/R/pkg/R/DataFrame.R
+++ b/R/pkg/R/DataFrame.R
@@ -790,9 +790,12 @@ setMethod("$", signature(x = "DataFrame"),
setMethod("$<-", signature(x = "DataFrame"),
function(x, name, value) {
- stopifnot(class(value) == "Column")
+ stopifnot(class(value) == "Column" || is.null(value))
cols <- columns(x)
if (name %in% cols) {
+ if (is.null(value)) {
+ cols <- Filter(function(c) { c != name }, cols)
+ }
cols <- lapply(cols, function(c) {
if (c == name) {
alias(value, name)
@@ -802,6 +805,9 @@ setMethod("$<-", signature(x = "DataFrame"),
})
nx <- select(x, cols)
} else {
+ if (is.null(value)) {
+ return(x)
+ }
nx <- withColumn(x, name, value)
}
x@sdf <- nx@sdf
diff --git a/R/pkg/inst/tests/test_sparkSQL.R b/R/pkg/inst/tests/test_sparkSQL.R
index 25831ae2d9..af7a6c5820 100644
--- a/R/pkg/inst/tests/test_sparkSQL.R
+++ b/R/pkg/inst/tests/test_sparkSQL.R
@@ -449,6 +449,11 @@ test_that("select operators", {
df$age2 <- df$age * 2
expect_equal(columns(df), c("name", "age", "age2"))
expect_equal(count(where(df, df$age2 == df$age * 2)), 2)
+
+ df$age2 <- NULL
+ expect_equal(columns(df), c("name", "age"))
+ df$age3 <- NULL
+ expect_equal(columns(df), c("name", "age"))
})
test_that("select with column", {