aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/R
diff options
context:
space:
mode:
Diffstat (limited to 'R/pkg/R')
-rw-r--r--R/pkg/R/functions.R58
-rw-r--r--R/pkg/R/generics.R8
2 files changed, 66 insertions, 0 deletions
diff --git a/R/pkg/R/functions.R b/R/pkg/R/functions.R
index e7decb9186..752e4c5c71 100644
--- a/R/pkg/R/functions.R
+++ b/R/pkg/R/functions.R
@@ -3745,3 +3745,61 @@ setMethod("collect_set",
jc <- callJStatic("org.apache.spark.sql.functions", "collect_set", x@jc)
column(jc)
})
+
+#' split_string
+#'
+#' Splits string on regular expression.
+#'
+#' Equivalent to \code{split} SQL function
+#'
+#' @param x Column to compute on
+#' @param pattern Java regular expression
+#'
+#' @rdname split_string
+#' @family string_funcs
+#' @aliases split_string,Column-method
+#' @export
+#' @examples \dontrun{
+#' df <- read.text("README.md")
+#'
+#' head(select(df, split_string(df$value, "\\s+")))
+#'
+#' # This is equivalent to the following SQL expression
+#' head(selectExpr(df, "split(value, '\\\\s+')"))
+#' }
+#' @note split_string 2.3.0
+setMethod("split_string",
+ signature(x = "Column", pattern = "character"),
+ function(x, pattern) {
+ jc <- callJStatic("org.apache.spark.sql.functions", "split", x@jc, pattern)
+ column(jc)
+ })
+
+#' repeat_string
+#'
+#' Repeats string n times.
+#'
+#' Equivalent to \code{repeat} SQL function
+#'
+#' @param x Column to compute on
+#' @param n Number of repetitions
+#'
+#' @rdname repeat_string
+#' @family string_funcs
+#' @aliases repeat_string,Column-method
+#' @export
+#' @examples \dontrun{
+#' df <- read.text("README.md")
+#'
+#' first(select(df, repeat_string(df$value, 3)))
+#'
+#' # This is equivalent to the following SQL expression
+#' first(selectExpr(df, "repeat(value, 3)"))
+#' }
+#' @note repeat_string 2.3.0
+setMethod("repeat_string",
+ signature(x = "Column", n = "numeric"),
+ function(x, n) {
+ jc <- callJStatic("org.apache.spark.sql.functions", "repeat", x@jc, numToInt(n))
+ column(jc)
+ })
diff --git a/R/pkg/R/generics.R b/R/pkg/R/generics.R
index 61d248ebd2..5e7a1c60c2 100644
--- a/R/pkg/R/generics.R
+++ b/R/pkg/R/generics.R
@@ -1192,6 +1192,10 @@ setGeneric("regexp_extract", function(x, pattern, idx) { standardGeneric("regexp
setGeneric("regexp_replace",
function(x, pattern, replacement) { standardGeneric("regexp_replace") })
+#' @rdname repeat_string
+#' @export
+setGeneric("repeat_string", function(x, n) { standardGeneric("repeat_string") })
+
#' @rdname reverse
#' @export
setGeneric("reverse", function(x) { standardGeneric("reverse") })
@@ -1257,6 +1261,10 @@ setGeneric("skewness", function(x) { standardGeneric("skewness") })
#' @export
setGeneric("sort_array", function(x, asc = TRUE) { standardGeneric("sort_array") })
+#' @rdname split_string
+#' @export
+setGeneric("split_string", function(x, pattern) { standardGeneric("split_string") })
+
#' @rdname soundex
#' @export
setGeneric("soundex", function(x) { standardGeneric("soundex") })