ianmcook commented on a change in pull request #10327:
URL: https://github.com/apache/arrow/pull/10327#discussion_r636523993
##########
File path: r/R/expression.R
##########
@@ -76,7 +76,15 @@
Expression <- R6Class("Expression", inherit = ArrowObject,
public = list(
ToString = function() compute___expr__ToString(self),
- type = function(schema) compute___expr__type(self, schema),
+ schema = NULL,
+ bind = function(schema) self$schema <- schema,
+ type = function() {
+ if (is.null(self$schema)) {
+ stop("Must bind() expression to a schema before returning its type",
call. = FALSE)
+ }
+ compute___expr__type(self, self$schema)
Review comment:
Just for posterity, here's the test code I ran
```r
library(dplyr)
library(arrow)
x <- as.data.frame(t(c(1:26)))
colnames(x) <- letters
x$z <- "z"
x <- Table$create(x)
start_time <- Sys.time()
for (i in 1:100) {
q <- x %>% relocate(where(is.numeric), .after = where(is.character))
w <- x %>% relocate(where(is.character), .before = where(is.numeric))
}
end_time <- Sys.time()
end_time - start_time
# ~8 seconds before change
# ~4 seconds after change
```
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]