Skip to content

SQL preview in Rmd "console" mode #6769

Open

Description

@isteves

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.

image

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: paged
editor_options:
  chunk_output_type: console
---

```{r}
library(dplyr)
library(dbplyr)
conn <- src_memdb()
conn_isolated <- conn$con #weird but seems necessary for the sql chunk
copy_to(conn,
        storms,
        overwrite = TRUE)

tbl(conn, sql("select * from storms limit 10"))
```

```{sql connection = conn_isolated}
select * from storms limit 10;
```

Activity

  1. R-Hannibal commented on May 20, 2020

    @R-Hannibal

    Thanks so much for raising this issue @isteves. We'll mark this ticket for review as we continue our ongoing development of RStudio.

  2. removed their assignment
    on May 20, 2020
  3. mikebessuille commented on Jan 25, 2021

    @mikebessuille
    Contributor

    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.

  4. added this to the Later milestone on Jan 25, 2021
  5. modified the milestones: Later, Future-1 on Nov 17, 2022
  6. self-assigned this
    on Nov 17, 2022
  7. removed their assignment
    on Jan 26, 2023
  8. modified the milestones: Backlog-1, Later on Sep 26, 2023
  9. ChristJohnson commented on Nov 6, 2024

    @ChristJohnson

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions