Skip to content

Commit 1464972

Browse files
author
Yuto Akutsu
committed
add secant and cosecant as R functions
1 parent 079a9c5 commit 1464972

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

R/pkg/NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ exportMethods("%<=>%",
267267
"crc32",
268268
"create_array",
269269
"create_map",
270+
"csc",
270271
"current_date",
271272
"current_timestamp",
272273
"hash",
@@ -393,6 +394,7 @@ exportMethods("%<=>%",
393394
"rtrim",
394395
"schema_of_csv",
395396
"schema_of_json",
397+
"sec",
396398
"second",
397399
"sha1",
398400
"sha2",

R/pkg/R/functions.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,19 @@ setMethod("crc32",
928928
column(jc)
929929
})
930930

931+
#' @details
932+
#' \code{csc}: Returns the cosecant of the given value.
933+
#'
934+
#' @rdname column_math_functions
935+
#' @aliases csc csc,Column-method
936+
#' @note csc since 3.3.0
937+
setMethod("csc",
938+
signature(x = "Column"),
939+
function(x) {
940+
jc <- callJStatic("org.apache.spark.sql.functions", "csc", x@jc)
941+
column(jc)
942+
})
943+
931944
#' @details
932945
#' \code{hash}: Calculates the hash code of given columns, and returns the result
933946
#' as an int column.
@@ -3390,6 +3403,19 @@ setMethod("rpad", signature(x = "Column", len = "numeric", pad = "character"),
33903403
column(jc)
33913404
})
33923405

3406+
#' @details
3407+
#' \code{sec}: Returns the secant of the given value.
3408+
#'
3409+
#' @rdname column_math_functions
3410+
#' @aliases sec sec,Column-method
3411+
#' @note sec since 3.3.0
3412+
setMethod("sec",
3413+
signature(x = "Column"),
3414+
function(x) {
3415+
jc <- callJStatic("org.apache.spark.sql.functions", "sec", x@jc)
3416+
column(jc)
3417+
})
3418+
33933419
#' @details
33943420
#' \code{substring_index}: Returns the substring from string (\code{x}) before \code{count}
33953421
#' occurrences of the delimiter (\code{delim}). If \code{count} is positive, everything the left of

R/pkg/R/generics.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,10 @@ setGeneric("create_array", function(x, ...) { standardGeneric("create_array") })
955955
#' @name NULL
956956
setGeneric("create_map", function(x, ...) { standardGeneric("create_map") })
957957

958+
#' @rdname column_math_functions
959+
#' @name NULL
960+
setGeneric("csc", function(x) { standardGeneric("csc") })
961+
958962
#' @rdname column_misc_functions
959963
#' @name NULL
960964
setGeneric("hash", function(x, ...) { standardGeneric("hash") })
@@ -1332,6 +1336,10 @@ setGeneric("schema_of_json", function(x, ...) { standardGeneric("schema_of_json"
13321336
#' @name NULL
13331337
setGeneric("sd", function(x, na.rm = FALSE) { standardGeneric("sd") })
13341338

1339+
#' @rdname column_math_functions
1340+
#' @name NULL
1341+
setGeneric("sec", function(x) { standardGeneric("sec") })
1342+
13351343
#' @rdname column_datetime_functions
13361344
#' @name NULL
13371345
setGeneric("second", function(x) { standardGeneric("second") })

R/pkg/tests/fulltests/test_sparkSQL.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ test_that("column functions", {
14351435
desc_nulls_first(c1) + desc_nulls_last(c1)
14361436
c29 <- acosh(c1) + asinh(c1) + atanh(c1)
14371437
c30 <- product(c1) + product(c1 * 0.5)
1438-
c31 <- cot(c1)
1438+
c31 <- sec(c1) + csc(c1) + cot(c1)
14391439

14401440
# Test if base::is.nan() is exposed
14411441
expect_equal(is.nan(c("a", "b")), c(FALSE, FALSE))

0 commit comments

Comments
 (0)