ianmcook commented on a change in pull request #10327: URL: https://github.com/apache/arrow/pull/10327#discussion_r637423216
########## File path: r/R/dplyr-functions.R ########## @@ -109,6 +126,55 @@ nse_funcs$as.numeric <- function(x) { Expression$create("cast", x, options = cast_options(to_type = float64())) } +# is.* type functions +nse_funcs$is.character <- function(x) { + x$type_id() %in% Type[c("STRING", "LARGE_STRING")] +} +nse_funcs$is.numeric <- function(x) { + x$type_id() %in% Type[c("UINT8", "INT8", "UINT16", "INT16", "UINT32", "INT32", + "UINT64", "INT64", "HALF_FLOAT", "FLOAT", "DOUBLE", + "DECIMAL", "DECIMAL256")] +} +nse_funcs$is.double <- function(x) { + x$type_id() == Type["DOUBLE"] +} +nse_funcs$is.integer <- function(x) { + x$type_id() %in% Type[c("UINT8", "INT8", "UINT16", "INT16", "UINT32", "INT32", + "UINT64", "INT64")] +} +nse_funcs$is.integer64 <- function(x) { + x$type_id() == Type["INT64"] +} +nse_funcs$is.logical <- function(x) { + x$type_id() == Type["BOOL"] +} +nse_funcs$is.factor <- function(x) { + x$type_id() == Type["DICTIONARY"] +} +nse_funcs$is.list <- function(x) { + x$type_id() %in% Type[c("LIST", "FIXED_SIZE_LIST", "LARGE_LIST")] +} + +# rlang::is_* type functions +nse_funcs$is_character <- function(x, n = NULL) { + nse_funcs$is.character(x) && (is.null(n) || length(x) == n) +} +nse_funcs$is_double <- function(x, n = NULL, finite = NULL) { + nse_funcs$is.double(x) && + (is.null(n) || length(x) == n) && + (is.null(finite) || + (finite && as.vector(!any(is_in(x, c(NA_real_, Inf,-Inf, NaN)))))) Review comment: TODO: wait until #10375 is merged, rebase, simplify this to use `is.finite()` -- 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: us...@infra.apache.org