Can I use R functions inside bigrquery ?

I'm trying to learn how to use bigrquery The following minimum example works.

library(bigrquery)
library(dplyr)
library(DBI)
bq_auth(path = "./BigQuery/imgc-185017-e5eb87ce53ee.json")


# This works --------------------------------------------------------------

con <- dbConnect(
  bigrquery::bigquery(),
  project = "publicdata",
  dataset = "samples",
  billing = "imgc-185017"
)

natality <- tbl(con, "natality")

test <- natality %>%
  select(month) %>% 
  head(10) %>%
  collect()

labs <- c(paste(seq(1, 12, by = 3), seq(3, 12, by = 3),
                sep = "-"))

test %>% 
  transmute(q = cut(month, breaks = c(seq(1, 12, by = 3), Inf), labels = labs, right = FALSE)) 

However, this code does not work:

test <- natality %>%
  select(month) %>% 
  head(10) %>%
  transmute(q = cut(month, breaks = c(seq(1, 12, by = 3), Inf), labels = labs, right = FALSE))  %>% 
  collect()

Error in vapply(x, escape, character(1), con = con) : 
  values must be length 1,
 but FUN(X[[2]]) result is length 2
In addition: Warning messages:
1: Named arguments ignored for SQL SEQ 
2: Named arguments ignored for SQL CUT 

What is the recommended way of doing this? The general idea is that I want to apply some R function to a big data set after doing some group_by.

Thanks!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.