knitr sql chunk不将数据保存到变量中 [英] knitr sql chunk not saving data into variable
问题描述
这里是一个例子
{r setup,include = FALSE,warning = FALSE,message = FALSE}
#加载必要的库
库(bigrquery )
library(knitr)
library(tidyverse)
$ b $ db
df< - NULL
```
```{sql,connection = db,output.var = df}
select * from example_dataset
limit 10
```
返回数据集
$ b $```{r}
head( df)
```
NULL
我试过这里的解决方案( R:Knitr给出SQL块的错误),但它没有解决我的问题。
Just ran进入相同的问题,它看起来像你需要引用你分配的变量。
```{sql,connection = db,output.var =df}
select * from example_dataset
limit 10
```
资料来源: http://rmarkdown.rstudio.com/ authoring_knitr_engines.html#sql
My RMarkdown notebook with a SQL chunk runs fine when I run all the chunks one by one interactively, but when I try to knit, the SQL chunk does not have save the data into the specified variable. When the dataset that was supposed to be generated using the SQL chunk is referenced in later R chunks, the dataset variable is simply empty.
Here's an example
{r setup, include=FALSE, warning=FALSE, message=FALSE}
# load necessary libraries
library(bigrquery)
library(knitr)
library(tidyverse)
db <- dbConnect(dbi_driver(), dataset = 'sandbox', project = 'project_id', use_legacy_sql = FALSE)
df <- NULL
```
```{sql, connection=db, output.var=df}
select * from example_dataset
limit 10
```
returns dataset
```{r}
head(df)
```
NULL
I've tried the solution here (R: Knitr gives error for SQL-chunk), but it didn't solve my problem.
Just ran into the same problem and it looks like you need to quote the variable you are assigning.
```{sql, connection=db, output.var="df"}
select * from example_dataset
limit 10
```
Source: http://rmarkdown.rstudio.com/authoring_knitr_engines.html#sql
这篇关于knitr sql chunk不将数据保存到变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!