Skip to content

Commit

Permalink
Merge branch 'release/2.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
psychelzh committed Jul 1, 2022
2 parents a248401 + f0ddd52 commit 7d1f2f2
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 50 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tarflow.iquizoo
Title: Setup "targets" Workflows for "iquzoo" Data Processing
Version: 2.3.2
Version: 2.4.0
Authors@R: c(
person("Liang", "Zhang", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9041-1150")),
Expand All @@ -18,11 +18,9 @@ Depends:
R (>= 4.1.0)
Imports:
bit64,
cachem,
data.iquizoo (>= 0.2.0),
DBI,
dplyr,
memoise,
odbc,
purrr,
rlang (>= 0.1.2),
Expand All @@ -32,13 +30,15 @@ Imports:
utils,
vctrs
Suggests:
cachem,
config,
covr,
fs,
future,
future.callr,
jsonlite,
lifecycle,
memoise,
mockery,
preproc.iquizoo (>= 2.4.0),
roxygen2,
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ export(insert_where_single_game)
export(pickup)
export(preproc_data)
export(search_games)
export(search_games_mem)
export(wrangle_data)
import(rlang)
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# tarflow.iquizoo 2.4.0

## Breaking Changes

* Removed `search_games_mem()` for it will not behave as expected. Especially, `memoise::forget()` will not work. A working version is added in rmarkdown template.

## Misc

* Enhanced code quality.

# tarflow.iquizoo 2.3.2

## Bug Fixes
Expand Down
16 changes: 1 addition & 15 deletions R/search_games.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@
#' @param query_file An optional argument specifying the file storing query of
#' games. If leave as `NULL`, default to "sql/games.tmpl.sql", which is
#' created by rmarkdown template.
#' @param file_cache The file used to store caches of results which is passed to
#' [cachem::cache_disk()].
#' @param ... Arguments passed to [search_games()].
#' @return A [tibble][tibble::tibble-package] contains all the games to be
#' analyzed and its related information.
#' @export
search_games <- function(config_where, known_only = TRUE, query_file = NULL) {
if (is.null(query_file)) query_file <- "sql/games.tmpl.sql"
if (!file.exists(query_file)) abort("Query file missing.", "query_file_miss")
games <- pickup(query_file, config_where)
join_method <- if (known_only) dplyr::inner_join else dplyr::left_join
games |>
join_method(data.iquizoo::game_info, by = names(games)) |>
dplyr::mutate(
# https://github.com/ropensci/tarchetypes/issues/94
game_id = bit64::as.character.integer64(game_id),
game_id = bit64::as.character.integer64(.data$game_id),
prep_fun = purrr::map(
.data[["prep_fun_name"]],
purrr::possibly(sym, NA)
Expand All @@ -39,13 +35,3 @@ search_games <- function(config_where, known_only = TRUE, query_file = NULL) {
)
)
}

#' @describeIn search_games Cached version using
#' [memoise()][memoise::memoise()].
#' @export
search_games_mem <- function(file_cache = "~/.cache.tarflow", ...) {
memoise::memoise(
search_games,
cache = cachem::cache_disk(file_cache)
)(...)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ targets::tar_unscript()

```{targets set-globals, tar_globals=TRUE, include=FALSE}
future::plan(future.callr::callr)
games <- tarflow.iquizoo::search_games_mem(config_where = config::get("where"))
search_games_mem <- memoise::memoise(
tarflow.iquizoo::search_games,
cache = cachem::cache_disk("~/.cache.tarflow")
)
games <- search_games_mem(config_where = config::get("where"))
tar_option_set(
package = c("tidyverse", "preproc.iquizoo", "tarflow.iquizoo"),
format = "qs",
Expand Down
14 changes: 0 additions & 14 deletions man/search_games.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions tests/testthat/dummy/test.sql

This file was deleted.

22 changes: 9 additions & 13 deletions tests/testthat/test-search_games.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
test_that("Correctly combine `game_info`", {
mockery::stub(
search_games, "pickup",
function(query_file, ...) {
tibble::tibble(read.csv(query_file)) |>
dplyr::mutate(game_id = bit64::as.integer64(game_id))
}
tibble::tibble(
game_id = bit64::as.integer64(
c("225528186135045", "225528186135046")
)
)
)
expect_snapshot_value(
search_games(query_file = "dummy/test.sql"),
search_games(),
style = "json2"
)
expect_snapshot_value(
search_games(known_only = FALSE, query_file = "dummy/test.sql"),
search_games(known_only = FALSE),
style = "json2"
)
})

test_that("Support `integer64`", {
mockery::stub(
search_games, "pickup",
function(query_file, ...)
tibble::tibble(game_id = bit64::as.integer64(225528186135045))
tibble::tibble(game_id = bit64::as.integer64(225528186135045))
)
expect_snapshot_value(
search_games(query_file = "dummy/test.sql"),
search_games(),
style = "json2"
)
})

test_that("Error when query file not found", {
expect_error(search_games(NULL), class = "query_file_miss")
})

0 comments on commit 7d1f2f2

Please sign in to comment.