From b4b16a66d01bde295be0facfc60ecd58c8799f7f Mon Sep 17 00:00:00 2001 From: Xin Ren Date: Wed, 3 Aug 2016 17:04:59 -0700 Subject: [PATCH 1/4] explicitly call show() --- R/pkg/R/DataFrame.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index a4733313ed16..1b399d81c91f 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -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", From c20321f6811b1aa687633ecdca9e1a29c1bdb053 Mon Sep 17 00:00:00 2001 From: Xin Ren Date: Wed, 3 Aug 2016 17:24:30 -0700 Subject: [PATCH 2/4] api Overloading --- R/pkg/R/DataFrame.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index 1b399d81c91f..ace45ced54c5 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -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", @@ -424,8 +424,8 @@ 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<-", From 022bb69b4cc04564b8521e8129d57d3d59aa05c5 Mon Sep 17 00:00:00 2001 From: Xin Ren Date: Wed, 3 Aug 2016 17:46:40 -0700 Subject: [PATCH 3/4] avoid duplicate parameters --- R/pkg/R/DataFrame.R | 14 +++++++------- R/pkg/R/generics.R | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index ace45ced54c5..a5df1c3165fc 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -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 @@ -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 #' @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. @@ -429,9 +429,9 @@ setMethod("coltypes", #'} #' @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") @@ -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)) { @@ -451,7 +451,7 @@ setMethod("coltypes<-", col } }) - nx <- select(x, newCols) + nx <- select(y, newCols) dataFrame(nx@sdf) }) diff --git a/R/pkg/R/generics.R b/R/pkg/R/generics.R index e7444ac2467d..01729ea7ddf4 100644 --- a/R/pkg/R/generics.R +++ b/R/pkg/R/generics.R @@ -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 From 6bdec22024b159952a4a8d43ec1348cd8702cf73 Mon Sep 17 00:00:00 2001 From: Xin Ren Date: Sun, 7 Aug 2016 23:28:40 -0700 Subject: [PATCH 4/4] leave out duplicate parameter 'x' --- R/pkg/R/DataFrame.R | 13 ++++++------- R/pkg/R/generics.R | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/R/pkg/R/DataFrame.R b/R/pkg/R/DataFrame.R index a5df1c3165fc..0ce4696198c7 100644 --- a/R/pkg/R/DataFrame.R +++ b/R/pkg/R/DataFrame.R @@ -358,7 +358,7 @@ setMethod("colnames<-", #' #' Get column types of a SparkDataFrame #' -#' @param x A SparkDataFrame whose column types to be get +#' @param x A SparkDataFrame #' @return value A character vector with the column types of the given SparkDataFrame #' @rdname coltypes #' @aliases coltypes,SparkDataFrame-method @@ -411,7 +411,6 @@ setMethod("coltypes", #' #' Set the column types of a SparkDataFrame. #' -#' @param y A SparkDataFrame whose column types to be set #' @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. @@ -429,9 +428,9 @@ setMethod("coltypes", #'} #' @note coltypes<- since 1.6.0 setMethod("coltypes<-", - signature(y = "SparkDataFrame", value = "character"), - function(y, value) { - cols <- columns(y) + signature(x = "SparkDataFrame", value = "character"), + function(x, value) { + cols <- columns(x) ncols <- length(cols) if (length(value) == 0) { stop("Cannot set types of an empty SparkDataFrame with no Column") @@ -440,7 +439,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(y, cols[i]) + col <- getColumn(x, cols[i]) if (!is.na(value[i])) { stype <- rToSQLTypes[[value[i]]] if (is.null(stype)) { @@ -451,7 +450,7 @@ setMethod("coltypes<-", col } }) - nx <- select(y, newCols) + nx <- select(x, newCols) dataFrame(nx@sdf) }) diff --git a/R/pkg/R/generics.R b/R/pkg/R/generics.R index 01729ea7ddf4..e7444ac2467d 100644 --- a/R/pkg/R/generics.R +++ b/R/pkg/R/generics.R @@ -428,7 +428,7 @@ setGeneric("coltypes", function(x) { standardGeneric("coltypes") }) #' @rdname coltypes #' @export -setGeneric("coltypes<-", function(y, value) { standardGeneric("coltypes<-") }) +setGeneric("coltypes<-", function(x, value) { standardGeneric("coltypes<-") }) #' @rdname columns #' @export