diff --git a/DESCRIPTION b/DESCRIPTION index 28fa945..8911db3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: looker3 Type: Package Title: looker3 (http://github.com/abelcastilloavant/avant-looker3) Description: Pull data from Looker using the fancy new 3.0 API. -Version: 0.1.2 +Version: 0.1.3 Author: Abel Castillo Maintainer: Abel Castillo Authors@R: c(person("Abel", "Castillo", diff --git a/R/looker3.R b/R/looker3.R index 082c113..a47300a 100644 --- a/R/looker3.R +++ b/R/looker3.R @@ -43,6 +43,20 @@ looker3 <- function(model, view, fields, checkr::validate(model %is% simple_string, view %is% simple_string, fields %is% character) + + if (is.character(filters)) { + filters <- colon_split_to_list(filters) + } + run_inline_query(looker_setup$LOOKER_URL, looker_setup$LOOKER_ID, looker_setup$LOOKER_SECRET, model, view, fields, filters, limit) } + + +colon_split_to_list <- function(string) { + colon_split <- strsplit(string, ": ") + field_names <- lapply(colon_split, `[[`, 1) + values <- lapply(colon_split, `[[`, 2) + names(values) <- field_names + values +} diff --git a/README.md b/README.md index 3117871..5aedbff 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,8 @@ df <- looker3(model = "thelook", ) ``` +Filters can be specified as above, or as a character string with colon separations, e.g. + +``` +filters = c("orders.created_month: 90 days", "orders.status: complete") +``` diff --git a/tests/testthat/test-looker3.R b/tests/testthat/test-looker3.R index 093c00b..8d3c020 100644 --- a/tests/testthat/test-looker3.R +++ b/tests/testthat/test-looker3.R @@ -53,7 +53,11 @@ withr::with_envvar(c( args <- list(model = "look", view = "items", fields = c("category.name", "products.count"), - filters = list(c("category.name", "socks"))) + filters = list("category.name" = "socks")) + + bw_compatible_args <- list(model = "look", view = "items", + fields = c("category.name", "products.count"), + filters = "category.name: socks") expect_equal(do.call(looker3, args), c(list(url = fake_env_vars$url, id = fake_env_vars$id, secret = fake_env_vars$secret), @@ -63,6 +67,11 @@ withr::with_envvar(c( c(list(url = fake_env_vars$url, id = fake_env_vars$id, secret = fake_env_vars$secret), args, list(limit = 20))) + + expect_equal(do.call(looker3, bw_compatible_args), + c(list(url = fake_env_vars$url, id = fake_env_vars$id, secret = fake_env_vars$secret), + args, + list(limit = 10))) }) })