You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I regularly use R and SQL together in Rmd's, usually using DBI::dbGetQuery() or dbplyr to bring data into R for manipulation. I recently explored some of the very cool SQL features within RStudio, and hope to incorporate more of them into my workflow.
One thing that stopped me from using SQL chunks a few months ago is the lack of a "preview" option when Rmd's have chunk_output_type: console.
I realized today (partially through this RStudio community discussion) that two SQL preview options are actually available in RStudio:
a) Using a .sql file and then adding -- !preview conn = <connection>
b) Using chunk_output_type: inline within an Rmd
It would be great if one of these options could be implemented for Rmd's in console mode. Had I realized there were other preview options, I probably would have started using these chunks sooner.
My example code:
---title: "R Notebook"output:
html_document:
df_print: pagededitor_options:
chunk_output_type: console---```{r}library(dplyr)library(dbplyr)conn <- src_memdb()conn_isolated <- conn$con #weird but seems necessary for the sql chunkcopy_to(conn, storms, overwrite = TRUE)tbl(conn, sql("select * from storms limit 10"))``````{sql connection = conn_isolated}
select * from storms limit 10;```
Reacted by Jouni Vatanen, Daniel Brannock, Tom Shafer, Ross Holmberg and Georg
The Run button sends R to the R console, which doesn't currently support SQL chunks. This would be a useful improvement. It doesn't directly match our short-term priorities, but would be interested in seeing how many people would benefit from this improvement.
Note, chunk_output_type: inline is assumed for many features in RStudio. For example, I just had the weirdest bug with the Notebook Preview system where it broke the preview if I tried to use console instead of inline. I believe this assumption is faulty and should be dealt with somehow (i.e. idiot proof the UI and "fix" notebook header settings).
Activity
R-Hannibal commentedon May 20, 2020
Thanks so much for raising this issue @isteves. We'll mark this ticket for review as we continue our ongoing development of RStudio.
mikebessuille commentedon Jan 25, 2021
The Run button sends R to the R console, which doesn't currently support SQL chunks. This would be a useful improvement. It doesn't directly match our short-term priorities, but would be interested in seeing how many people would benefit from this improvement.
ChristJohnson commentedon Nov 6, 2024
Note,
chunk_output_type: inlineis assumed for many features in RStudio. For example, I just had the weirdest bug with the Notebook Preview system where it broke the preview if I tried to useconsoleinstead ofinline. I believe this assumption is faulty and should be dealt with somehow (i.e. idiot proof the UI and "fix" notebook header settings).