Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions R/pkg/R/DataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ setMethod("showDF",
#' sparkR.session()
#' path <- "path/to/file.json"
#' df <- read.json(path)
#' df
#' show(df)
#'}
#' @note show(SparkDataFrame) since 1.4.0
setMethod("show", "SparkDataFrame",
Expand Down Expand Up @@ -358,7 +358,7 @@ setMethod("colnames<-",
#'
#' Get column types of a SparkDataFrame
#'
#' @param x A SparkDataFrame
#' @param x A SparkDataFrame whose column types to be get
#' @return value A character vector with the column types of the given SparkDataFrame
#' @rdname coltypes
#' @aliases coltypes,SparkDataFrame-method
Expand All @@ -368,7 +368,7 @@ setMethod("colnames<-",
#' @examples
#'\dontrun{
#' irisDF <- createDataFrame(iris)
#' coltypes(irisDF)
#' coltypes(irisDF) # get column types
#'}
#' @note coltypes since 1.6.0
setMethod("coltypes",
Expand Down Expand Up @@ -411,7 +411,7 @@ setMethod("coltypes",
#'
#' Set the column types of a SparkDataFrame.
#'
#' @param x A SparkDataFrame
#' @param y A SparkDataFrame whose column types to be set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason you change this from x to y?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid duplicate variables, now it has 2 'x' in 'ARGUMENTS' section, or is there a better way to do it?

http://spark.apache.org/docs/2.0.0/api/R/coltypes.html

https://cloud.githubusercontent.com/assets/3925641/17386808/effb98ce-59a2-11e6-9657-d477d258a80c.png

Copy link
Member

@felixcheung felixcheung Aug 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - it's common in R to get the getter/setter method to share the same document page, and even parameter lists, eg.
https://stat.ethz.ch/R-manual/R-devel/library/base/html/colnames.html

I think the best way to do that is not to rename it to y, but leave out the @param x for coltype<-

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I'll try to do it, thanks Felix

#' @param value A character vector with the target column types for the given
#' SparkDataFrame. Column types can be one of integer, numeric/double, character, logical, or NA
#' to keep that column as-is.
Expand All @@ -424,14 +424,14 @@ setMethod("coltypes",
#' sparkR.session()
#' path <- "path/to/file.json"
#' df <- read.json(path)
#' coltypes(df) <- c("character", "integer")
#' coltypes(df) <- c(NA, "numeric")
#' coltypes(df) <- c("character", "integer") # set column types
#' coltypes(df) <- c(NA, "numeric") # set column types
#'}
#' @note coltypes<- since 1.6.0
setMethod("coltypes<-",
signature(x = "SparkDataFrame", value = "character"),
function(x, value) {
cols <- columns(x)
signature(y = "SparkDataFrame", value = "character"),
function(y, value) {
cols <- columns(y)
ncols <- length(cols)
if (length(value) == 0) {
stop("Cannot set types of an empty SparkDataFrame with no Column")
Expand All @@ -440,7 +440,7 @@ setMethod("coltypes<-",
stop("Length of type vector should match the number of columns for SparkDataFrame")
}
newCols <- lapply(seq_len(ncols), function(i) {
col <- getColumn(x, cols[i])
col <- getColumn(y, cols[i])
if (!is.na(value[i])) {
stype <- rToSQLTypes[[value[i]]]
if (is.null(stype)) {
Expand All @@ -451,7 +451,7 @@ setMethod("coltypes<-",
col
}
})
nx <- select(x, newCols)
nx <- select(y, newCols)
dataFrame(nx@sdf)
})

Expand Down
2 changes: 1 addition & 1 deletion R/pkg/R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ setGeneric("coltypes", function(x) { standardGeneric("coltypes") })

#' @rdname coltypes
#' @export
setGeneric("coltypes<-", function(x, value) { standardGeneric("coltypes<-") })
setGeneric("coltypes<-", function(y, value) { standardGeneric("coltypes<-") })

#' @rdname columns
#' @export
Expand Down