aboutsummaryrefslogtreecommitdiff
path: root/R
diff options
context:
space:
mode:
authoractuaryzhang <actuaryzhang10@gmail.com>2017-03-01 12:35:56 -0800
committerFelix Cheung <felixcheung@apache.org>2017-03-01 12:35:56 -0800
commit2ff1467d676c9671da231db86bdc8e09c7450f80 (patch)
tree5841c3f7d8d37e0e17140468eb43568bcc54ea31 /R
parent417140e441505f20eb5bd4943ce216c3ec6adc10 (diff)
downloadspark-2ff1467d676c9671da231db86bdc8e09c7450f80.tar.gz
spark-2ff1467d676c9671da231db86bdc8e09c7450f80.tar.bz2
spark-2ff1467d676c9671da231db86bdc8e09c7450f80.zip
[DOC][MINOR][SPARKR] Update SparkR doc for names, columns and colnames
Update R doc: 1. columns, names and colnames returns a vector of strings, not **list** as in current doc. 2. `colnames<-` does allow the subset assignment, so the length of `value` can be less than the number of columns, e.g., `colnames(df)[1] <- "a"`. felixcheung Author: actuaryzhang <actuaryzhang10@gmail.com> Closes #17115 from actuaryzhang/sparkRMinorDoc.
Diffstat (limited to 'R')
-rw-r--r--R/pkg/R/DataFrame.R4
-rw-r--r--R/pkg/inst/tests/testthat/test_sparkSQL.R6
2 files changed, 8 insertions, 2 deletions
diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R
index cc4cfa3423..e33d0d8e29 100644
--- a/R/pkg/R/DataFrame.R
+++ b/R/pkg/R/DataFrame.R
@@ -280,7 +280,7 @@ setMethod("dtypes",
#' Column Names of SparkDataFrame
#'
-#' Return all column names as a list.
+#' Return a vector of column names.
#'
#' @param x a SparkDataFrame.
#'
@@ -338,7 +338,7 @@ setMethod("colnames",
})
#' @param value a character vector. Must have the same length as the number
-#' of columns in the SparkDataFrame.
+#' of columns to be renamed.
#' @rdname columns
#' @aliases colnames<-,SparkDataFrame-method
#' @name colnames<-
diff --git a/R/pkg/inst/tests/testthat/test_sparkSQL.R b/R/pkg/inst/tests/testthat/test_sparkSQL.R
index ce0f5a198a..1dd8c5ce6c 100644
--- a/R/pkg/inst/tests/testthat/test_sparkSQL.R
+++ b/R/pkg/inst/tests/testthat/test_sparkSQL.R
@@ -898,6 +898,12 @@ test_that("names() colnames() set the column names", {
expect_equal(names(z)[3], "c")
names(z)[3] <- "c2"
expect_equal(names(z)[3], "c2")
+
+ # Test subset assignment
+ colnames(df)[1] <- "col5"
+ expect_equal(colnames(df)[1], "col5")
+ names(df)[2] <- "col6"
+ expect_equal(names(df)[2], "col6")
})
test_that("head() and first() return the correct data", {