英文:
Xaringan does render a chunk with chunk option class.source defined. How to solve it?
问题
I am using xaringan
to create slides with stan code. I want to present the model code and save it using the syntax below. However, when I add the class.source = "stan"
(to highlight the stan syntax appropriately) option the code does not render as it should:
---
output: xaringan::moon_reader
---
---
```{cat, engine.opts = list(file = 'code/stan/ex1.stan'), name = "ex1.stan", class.source = "stan"}
data {
int<lower=0> N; //number of data
vector[N] x; //covariates
vector[N] y; //variates
}
parameters {
real alpha; //intercept
real beta; //slope
real<lower=0> sigma; //scatter
}
model {
//priors
alpha ~ normal(0, 10);
beta ~ normal(0, 10);
sigma ~ normal(0, 1);
y ~ normal(alpha + beta * x, sigma); //likelihood
}
So the desired result would be:
[1]: https://i.stack.imgur.com/o6wNv.png
[2]: https://i.stack.imgur.com/LiV8z.png
<details>
<summary>英文:</summary>
I am using `xaringan` to create slides with stan code. I want to present the model code and save it using the syntax below. However, when I add the `class.source = "stan"` (to highlight the stan syntax appropriately) option the code does not render as it should:
```r
---
output: xaringan::moon_reader
---
---
```{cat, engine.opts = list(file = 'code/stan/ex1.stan'), name = "ex1.stan", class.source = "stan"}
data {
int<lower=0> N; //number of data
vector[N] x; //covariates
vector[N] y; //variates
}
parameters {
real alpha; //intercept
real beta; //slope
real<lower=0> sigma; //scatter
}
model {
//priors
alpha ~ normal(0, 10);
beta ~ normal(0, 10);
sigma ~ normal(0, 1);
y ~normal(alpha + beta * x, sigma); //likelihood
}
So the desired result would be:
答案1
得分: 2
根据您在上面的评论中的理解,您只需要以下内容的翻译:
---
output: xaringan::moon_reader
---
---
```{cat, engine.opts = list(file = "test.stan", lang = "stan")}
data {
int<lower=0> N; //数据数量
vector[N] x; //协变量
vector[N] y; //变量
}
parameters {
real alpha; //截距
real beta; //斜率
real<lower=0> sigma; //散射
}
model {
//先验分布
alpha ~ normal(0, 10);
beta ~ normal(0, 10);
sigma ~ normal(0, 1);
y ~ normal(alpha + beta * x, sigma); //似然
}
<details>
<summary>英文:</summary>
As I understand you in comments above, you simply need this:
---
output: xaringan::moon_reader
---
---
```{cat, engine.opts = list(file = "test.stan", lang = "stan")}
data {
int<lower=0> N; //number of data
vector[N] x; //covariates
vector[N] y; //variates
}
parameters {
real alpha; //intercept
real beta; //slope
real<lower=0> sigma; //scatter
}
model {
//priors
alpha ~ normal(0, 10);
beta ~ normal(0, 10);
sigma ~ normal(0, 1);
y ~normal(alpha + beta * x, sigma); //likelihood
}
```
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论