-
-
Notifications
You must be signed in to change notification settings - Fork 878
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
Add expand Option to SQL Engine #1357
Conversation
R/engine.R
Outdated
@@ -538,8 +538,11 @@ eng_sql = function(options) { | |||
# assign varname if requested | |||
if (!is.null(varname)) assign(varname, data, envir = knit_global()) | |||
|
|||
# reset query to pre-interpolated if not expanding | |||
if (!isTRUE(options$expand)) query <- options$code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will change the default behavior, i.e. previously the default is to expand the query, and now the default is to show raw query (because options$expand
is NULL
by default). I'd use
if (isFALSE(options$sql.expand))
so that users have to set sql.expand = FALSE
explicitly to present the query that is not interpolated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong but I think the previous default behavior is to show query uninterpolated because it is returning engine_output(options, options$code, output)
and options$code
is before interpolation.
I am indifferent what should be the default behavior. I have found both equally common in my writing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you are correct. I was wrong. Sorry.
I renamed the option to ` ``{sql x, connection=db}
SELECT ?x
` ``
` ``{sql x, connection=db, eval=FALSE, sql.show_interpolated=TRUE}
` ``
So I can show interpolated SQL at the appendix section of my writing. |
Okay, this makes perfect sense to me now. Please add a NEWS item to NEWS.md, your name to DESCRIPTION as a contributor ( |
b17f3b5
to
ac9e774
Compare
`sql.show_interpolated` chunk option, when set to `TRUE`, will render interpolated SQL query instead. This also works when `eval=FALSE`. Details: SQL chunk is awesome way to showcase SQL queries in syntax highlighted fashion. The support of interpolation is also great to allow further flexibility. While most the time I like showing uninterpolated SQL which is simple and easy to reason, sometimes I wish I can show interpolated SQL instead. This allows me to construct more complex SQL programatically but show readers the end results.
Thanks! Done and commits squashed. |
👍 |
SQL chunk is an awesome way to showcase SQL queries in syntax highlighted fashion. The support of interpolation is also great to allow further flexibility. While most the time I like showing uninterpolated SQL which is simple and easy to reason, sometimes I wish I can show interpolated SQL instead. This allows me to construct more complex SQL programmatically but show readers the end results.
This PR adds a new option
expand
for SQL engine, which would show interpolated SQL query in the code chunk.I am open to any suggestion for a better name. Let me know if you can think of a better idea. Thank you!
Putting a space between ` so code block works correctly.