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
integrate jcheng5/knitsql as knitr engine #1241
Conversation
| eng_sql = function(options) { | ||
| # Return char vector of sql interpolation param names | ||
| varnames_from_sql <- function(conn, sql) { | ||
| varPos <- DBI::sqlParseVariables(conn, sql) |
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.
I think we are going to want the DBI package to be a Suggests dependencies, which implies that we should preface our calls to DBI with a loadable check (see
Line 795 in 07b79a9
| loadable = function(pkg) requireNamespace(pkg, quietly = TRUE) |
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.
Putting DBI in Suggests is enough. If it is not installed or loadable, R will just signal an error here. I use loadable() when the package is not absolutely needed, which is not true here.
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.
Updated to only use suggests
|
Another thought aimed at preventing performance problems when exploring large datasets: if there is no |
|
|
||
| args <- if (length(names) > 0) { | ||
| setNames( | ||
| mget(names, inherits = inherits), |
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.
I guess we also need envir = env for mget().
|
A related suggestion: @yihui What would you think about importing the tibble (https://cran.r-project.org/web/packages/tibble/index.html) package for printing data frames within knitr? I guess you could also just check whether it is installed and use it in that case. Alternatively we could do the same thing in rmarkdown. |
|
I think the I definitely prefer tibble's printing behavior over R's default, so yes, |
|
Another more robust way to implement the LIMIT suggestions is to use Glad you like the tibble idea, Javier let's do it as Yihui suggests (and On Wed, Jul 13, 2016 at 5:41 AM, Yihui Xie notifications@github.com wrote:
|
|
Oh yeah, passing the limit as a function argument should be more robust than manipulating the SQL code directly. |
|
@javierluraschi Could you merge master into this PR (I want to provide instructions for installing from the PR branch and I want the branch to include the recent Rcpp work we did) |
|
@jjallaire merged to master + added tibble dependency. |
| @@ -101,7 +101,8 @@ Suggests: | |||
| jpeg, | |||
| XML, | |||
| RCurl, | |||
| DBI | |||
| DBI, | |||
| tibble | |||
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.
You also need the bit that Yihui provided to use tibble to do the printing when it's available (i.e. loadable).
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.
Thanks updated.
|
A couple more changes I think we still need here:
|
|
Yeah these are simple enough, so I'm adding them now. |
|
All done now. For 2, the chunk option is |
|
I have one more idea that I may want to explore for data display (will send a PR tomorrow or Monday but just wanted to put it out there for discussion). If we know we are in rmarkdown we could display the data using |
|
Coincidently I also thought for a while about using |

This PR adds a SQL engine for knitr to allow chunks based on DBI that look like:
This change comes from integrating https://github.com/jcheng5/knitsql adding a sample
.Rmdfile and removing theyamlconfiguration feature.