Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue with SQL chunk when cache=TRUE and output.var is specified #1542

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,10 @@ eng_sql = function(options) {
if (options$results == 'hide') output = NULL

# assign varname if requested
if (!is.null(varname)) assign(varname, data, envir = knit_global())
if (!is.null(varname)) {
assign(varname, data, envir = knit_global())
saveRDS(data, file = paste0(options$hash, "_sql_result.rds"))
}

# reset query to pre-interpolated if not expanding
if (!isTRUE(options$sql.show_interpolated)) query <- options$code
Expand All @@ -614,6 +617,13 @@ eng_sql = function(options) {
engine_output(options, query, output)
}

cache_eng_sql = function(options) {
varname <- options$output.var
if (!is.null(varname)) {
assign(varname, readRDS(paste0(options$hash, "_sql_result.rds")), envir = knit_global())
}
}

# go engine, added by @hodgesds https://github.com/yihui/knitr/pull/1330
eng_go = function(options) {
f = tempfile('code', '.', fileext = ".go")
Expand Down Expand Up @@ -666,7 +676,8 @@ knit_engines$set(
python = eng_python, julia = eng_julia
)

cache_engines$set(python = cache_eng_python)
cache_engines$set(python = cache_eng_python,
sql = cache_eng_sql)

get_engine = function(name) {
fun = knit_engines$get(name)
Expand Down