knitr有时不适当地将代码包装成块

knitr有时不适当地将代码包装成块,r,latex,knitr,beamer,R,Latex,Knitr,Beamer,在生成LaTeX beamer演示文稿的.Rnw文件中,我发现偶尔knitr会导致区块中的代码换行,就像是连续文本一样,即使区块选项tidy=FALSE有效(我已将其设置为默认值) 大多数代码块的格式都正确。下面是几个被包装的块的例子 It is often useful to plot the data for the binary distinction between $y_i = 0$ vs. $y_i > 0 $ as in logistic regression mod

在生成LaTeX beamer演示文稿的
.Rnw
文件中,我发现偶尔
knitr
会导致区块中的代码换行,就像是连续文本一样,即使区块选项
tidy=FALSE
有效(我已将其设置为默认值)

大多数代码块的格式都正确。下面是几个被包装的块的例子

  It is often useful to plot the data for the binary distinction between $y_i = 0$
  vs. $y_i > 0 $ as in logistic regression models.

<<phd-zero, h=5, w=5, out.width='0.5\\textwidth', size='footnotesize' >>=
plot(factor(articles==0) ~ mentor, data=PhdPubs,
    ylevels=2:1, ylab="Zero articles",
    breaks=quantile(mentor, probs=seq(0,1,.2)), cex.lab=1.25)
@
绘制$y_i=0之间二进制差异的数据通常很有用$
与逻辑回归模型中的$y_i>0$as相比。
=
绘图(系数(文章==0)~mentor,数据=PhdPubs,
ylevels=2:1,ylab=“零篇文章”,
中断=分位数(mentor,probs=seq(0,1,2)),cex.lab=1.25)
@
这些照片是这样的:

下面是另一个例子:

    For simplicity, we use all predictors for both the zero model
    and the non-zero model.

<<size='footnotesize', tidy=FALSE>>=
library(countreg)
phd.zip <- zeroinfl(articles ~ ., data=PhdPubs, dist="poisson")
phd.znb <- zeroinfl(articles ~ ., data=PhdPubs, dist="negbin")

phd.hp  <- hurdle(articles ~ ., data=PhdPubs, dist="poisson")
phd.hnb <- hurdle(articles ~ ., data=PhdPubs, dist="negbin")
@
为了简单起见,我们对零模型和零模型都使用了所有的预测值
以及非零模型。
=
图书馆(countreg)

phd.zip当您忘记对框架使用
[fragile]
选项时,会出现此行为。这通常会导致错误,但在本例中,它神秘地导致观察到的格式错误

这项工作:

\begin{frame}[fragile]
  \frametitle{Example: Phd Publications}
    For simplicity, we use all predictors for both the zero model
    and the non-zero model.

<<fit-models, size='footnotesize', tidy=FALSE>>=
library(countreg)
phd.zip <- zeroinfl(articles ~ ., data=PhdPubs, dist="poisson")
phd.znb <- zeroinfl(articles ~ ., data=PhdPubs, dist="negbin")

phd.hp  <- hurdle(articles ~ ., data=PhdPubs, dist="poisson")
phd.hnb <- hurdle(articles ~ ., data=PhdPubs, dist="negbin")
@
\end{frame}
\begin{frame}[脆弱]
\框架标题{示例:博士论文}
为了简单起见,我们对零模型和零模型都使用了所有的预测器
以及非零模型。
=
图书馆(countreg)
zip博士