Skip to content

Commit 2ff1467

Browse files
actuaryzhangFelix Cheung
authored andcommitted
[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 <[email protected]> Closes #17115 from actuaryzhang/sparkRMinorDoc.
1 parent 417140e commit 2ff1467

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

R/pkg/R/DataFrame.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ setMethod("dtypes",
280280

281281
#' Column Names of SparkDataFrame
282282
#'
283-
#' Return all column names as a list.
283+
#' Return a vector of column names.
284284
#'
285285
#' @param x a SparkDataFrame.
286286
#'
@@ -338,7 +338,7 @@ setMethod("colnames",
338338
})
339339

340340
#' @param value a character vector. Must have the same length as the number
341-
#' of columns in the SparkDataFrame.
341+
#' of columns to be renamed.
342342
#' @rdname columns
343343
#' @aliases colnames<-,SparkDataFrame-method
344344
#' @name colnames<-

R/pkg/inst/tests/testthat/test_sparkSQL.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,12 @@ test_that("names() colnames() set the column names", {
898898
expect_equal(names(z)[3], "c")
899899
names(z)[3] <- "c2"
900900
expect_equal(names(z)[3], "c2")
901+
902+
# Test subset assignment
903+
colnames(df)[1] <- "col5"
904+
expect_equal(colnames(df)[1], "col5")
905+
names(df)[2] <- "col6"
906+
expect_equal(names(df)[2], "col6")
901907
})
902908

903909
test_that("head() and first() return the correct data", {

0 commit comments

Comments
 (0)