You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/07/06 13:34:01 UTC

[GitHub] [arrow] pachadotdev commented on a change in pull request #10624: ARROW-12992: [R] bindings for substr(), substring(), str_sub()

pachadotdev commented on a change in pull request #10624:
URL: https://github.com/apache/arrow/pull/10624#discussion_r664559978



##########
File path: r/R/dplyr-functions.R
##########
@@ -280,6 +280,45 @@ nse_funcs$str_trim <- function(string, side = c("both", "left", "right")) {
   Expression$create(trim_fun, string)
 }
 
+nse_funcs$substr <- function(string, start, stop) {
+  assert_that(
+    length(start) == 1,
+    msg = "Start of length != 1 not supported in Arrow"
+  )
+  assert_that(
+    length(end) == 1,
+    msg = "End of length != 1 not supported in Arrow"
+  )
+
+  if (start > stop) {
+    start <- 0
+    stop <- 0
+  } else {
+    start <- max(0, start - 1)
+    stop <- max(0, stop)
+    start_stop <- c(min(start, stop), max(start, stop))
+    start <- start_stop[1]
+    stop <- start_stop[2]
+  }

Review comment:
       it's more a verification than a formal requirement




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org