Example Rmd file:
---
title: "Untitled"
output: html_document
---
\```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
\```
## R
\```{r cars}
library(tidyverse)
library(dbplyr)
library(DBI)
library(glue)
iris_db <- tbl_memdb(iris)
example_con <- src_memdb()$con
var1 <- "setosa"
\```
## SQL Chunks With Variable
### works fine, returns a new df some_df
\```{sql connection=example_con, include=FALSE, output.var="some_df"}
select
`Sepal.Width`,
*
from iris
where Species = ?var1
\```
### does not run
\```{sql connection=example_con, include=FALSE, output.var="some_other_df"}
select
`Sepal.Width` as concat("Sepal.Width", "-", ?var1),
--`Sepal.Width` as paste0("Sepal.Width", "-", ?var1), -- tried this too
*
from iris
where Species = ?var1
\```
Desired outcome is to return a new df, 'some_other_df' with field:
Sepal.Width-setosa
where 'setosa' has been appended to a alias from an r variable. Is this possible?