Github user shivaram commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8266#discussion_r37370414
  
    --- Diff: R/pkg/R/column.R ---
    @@ -203,3 +203,49 @@ setMethod("%in%",
                 jc <- callJMethod(x@jc, "in", table)
                 return(column(jc))
               })
    +
    +
    +#' when
    +#'
    +#' Evaluates a list of conditions and returns one of multiple possible 
result expressions.
    +#' If otherwise is not defined at the end, null is returned for unmatched 
conditions.
    +#'
    +#' @rdname column
    +setMethod("when",
    +          signature(x = "Column", y = "character", z = "ANY"),
    +          function(x, y, z) {
    +            condition <- y
    +            value <- z
    +            jc <- callJMethod(x@jc, "when", condition, value)
    +            column(jc)
    +          })
    +
    +#' otherwise
    +#' 
    +#' Evaluates a list of conditions and returns one of multiple possible 
result expressions.
    +#' If otherwise is not defined at the end, null is returned for unmatched 
conditions.
    +#'
    +#' @rdname column
    +setMethod("otherwise",
    +          signature(x = "Column", value = "ANY"),
    +          function(x, value) {
    +            value <- ifelse(class(value) == "Column", value@jc, value)
    +            jc <- callJMethod(x@jc, "otherwise", value)
    +            column(jc)
    +          })
    +
    +#' otherwise
    +#'
    +#' This is an alias of `otherwise` as an infix operator.
    +#'
    +#' @rdname column
    +#' @aliases otherwise
    +#' @examples
    +#' \dontrun{
    +#'   when(df$x > 1 & df$y < 10, 0) %otherwise% 1
    +#' }
    +setMethod("%otherwise%",
    --- End diff --
    
    `ifelse` can be a R-only function as its useful for R users who are 
familiar with it. If we can implement using when otherwise that'll be great ! 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to