1

I am preparing R markdown document and I would like to display postgre sql codes nicely in R markdown document of course the codes should only be displayed not runned. How can I do that? . Below I put some code examples.

Thank you.


title: "POSTGRE sql "
output:
html_document: default
pdf_document: default
 ---


```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

  ```{r1, eval=F}
  with data as (select * from (values
('03-05-2019'::date,'{"color": true,"view": [181] ,"school": 
[805,812,852,856,857]}'::jsonb),
('06-08-2019'::date,'{"color": false,"view": [184,185],"school": 
[805,855,859]}'::jsonb),
('04-07-2019'::date,'{"color": true,"view": [184,185,189],"school": 
[855,859]}'::jsonb)
) as v(published_date,attributes))
```
melik
  • 1,268
  • 3
  • 21
  • 42
  • Possible duplicate of [Hiding the R code in Rmarkdown/knit and just showing the results](https://stackoverflow.com/questions/13091112/hiding-the-r-code-in-rmarkdown-knit-and-just-showing-the-results) – NelsonGon Jun 07 '19 at 13:23
  • 1
    Not sure but why do you use `r1`? – NelsonGon Jun 07 '19 at 13:24

1 Answers1

1

In the header add this to your output

output:
  html_document:
    highlight: pygments

and in the body use this line

{r, engine = 'sql', eval = FALSE}

I am not sure the major differences in SQL and PostgreSQL, but the syntax highlighting does work. Here is a link to show other languages you can use with pygments http://pygments.org/languages/

John Carty
  • 242
  • 2
  • 13