Skip to content

Commit

Permalink
params object name recognized as dependency (#17)
Browse files Browse the repository at this point in the history
* pass object name to target deps

* add NEWS
  • Loading branch information
daranzolin authored Jul 16, 2024
1 parent 35e9987 commit 9c4134c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Included 'jinjar' as a dependency, allowing jinja-like SQL queries
* Breaking change: `query_params` argument in `tar_sql()` is now `params`.
* Additional tests
* `params` object name now recognized as a dependency.

# sqltargets 0.1.0

Expand Down
6 changes: 5 additions & 1 deletion R/tar_sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ tar_sql <- function(name,
check_pkg_installed("DBI")
check_pkg_installed("glue")

params_nm <- deparse(substitute(params))

name <- targets::tar_deparse_language(substitute(name))
params <- targets::tar_tidy_eval(
expr = substitute(params),
envir = targets::tar_option_get("envir"),
tidy_eval = tidy_eval
)


tar_sql_raw(
name = name,
path = path,
Expand All @@ -87,6 +90,7 @@ tar_sql <- function(name,
priority = priority,
resources = resources,
retrieval = retrieval,
cue = cue
cue = cue,
params_nm = params_nm
)
}
5 changes: 3 additions & 2 deletions R/tar_sql_raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#' that are passed to `jinjar::render()`. The list is quoted
#' (not evaluated until the target runs)
#' so that upstream targets can serve as parameter values.
#' @param params_nm Character of length 1, name of object passed to `params`.
#' @examples
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.
#' # Unparameterized SQL query:
Expand Down Expand Up @@ -62,7 +63,7 @@ tar_sql_raw <- function(
resources = targets::tar_option_get("resources"),
retrieval = targets::tar_option_get("retrieval"),
cue = targets::tar_option_get("cue"),
deps = deps
params_nm = NULL
) {
targets::tar_assert_scalar(name)
targets::tar_assert_chr(name)
Expand Down Expand Up @@ -111,7 +112,7 @@ tar_sql_raw <- function(
resources = resources,
retrieval = retrieval,
cue = cue,
deps = c(deps, file_dep)
deps = c(deps, params_nm, file_dep)
)

tar_sql_target_list(
Expand Down
6 changes: 2 additions & 4 deletions man/tar_sql_raw.Rd

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

0 comments on commit 9c4134c

Please sign in to comment.