我用它来生成一些 R 分析的输出。有些代码在文件编译 Sweave
时会生成超出右边距的长行。.tex
我在下面粘贴了一个例子Schunk
,你可以看到有些行有多长。我认为 sSchunk
是按逐字排版的。
有没有办法可以防止这些部分超出右边距?
谢谢。
\begin{Schunk}
\begin{Sinput}
> load("/media/working/working_files/R_working/survey_OM.RData")
> summary(lm(survey_OM$perc.OM[survey_OM$lake == "GTH 91" & survey_OM$depth ==
+ "hypo" & survey_OM$sed > 0] ~ survey_OM$sed[survey_OM$lake ==
+ "GTH 91" & survey_OM$depth == "hypo" & survey_OM$sed > 0]))
\end{Sinput}
\begin{Soutput}
Call:
lm(formula = survey_OM$perc.OM[survey_OM$lake == "GTH 91" & survey_OM$depth ==
"hypo" & survey_OM$sed > 0] ~ survey_OM$sed[survey_OM$lake ==
"GTH 91" & survey_OM$depth == "hypo" & survey_OM$sed > 0])
Residuals:
Min 1Q Median 3Q Max
-1.62011 -0.63241 0.04838 0.61389 2.81551
Coefficients:
Estimate
(Intercept) 23.06997
survey_OM$sed[survey_OM$lake == "GTH 91" & survey_OM$depth == "hypo" & survey_OM$sed > 0] -0.07520
Std. Error
(Intercept) 0.44174
survey_OM$sed[survey_OM$lake == "GTH 91" & survey_OM$depth == "hypo" & survey_OM$sed > 0] 0.07685
t value
(Intercept) 52.226
survey_OM$sed[survey_OM$lake == "GTH 91" & survey_OM$depth == "hypo" & survey_OM$sed > 0] -0.978
Pr(>|t|)
(Intercept) <2e-16
survey_OM$sed[survey_OM$lake == "GTH 91" & survey_OM$depth == "hypo" & survey_OM$sed > 0] 0.338
(Intercept) ***
survey_OM$sed[survey_OM$lake == "GTH 91" & survey_OM$depth == "hypo" & survey_OM$sed > 0]
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.004 on 23 degrees of freedom
(2 observations deleted due to missingness)
Multiple R-squared: 0.03996, Adjusted R-squared: -0.001778
F-statistic: 0.9574 on 1 and 23 DF, p-value: 0.338
\end{Soutput}
答案1
根据常见问题解答,Sweave 尊重在 R/S 中指定所需线长度的通常方式,即设置
options(width=40)
将限制输出的列数为 40。
但是,针对您的具体情况,我建议您更改 R 公式,使其变为
lm(perc.OM ~ sed, data=survey_OM, subset=lake == "GTH 91" & depth == "hypo" & sed > 0)
它看起来更像 R'ish,并且有利于阅读回归系数表,同时减少输出的长度。
答案2
我还没有尝试过,看看它是否适合你,但 Sweave FAQ(见http://www.statistik.lmu.de/~leisch/Sweave/FAQ.html)有一种方法可以改变S输入和输出的线长。
A.14 如何改变S输入和输出的线长?
Sweave 遵循在 S 中指定所需行长度的通常方式,即 options(width)。例如,在 options(width=40) 之后,行将被格式化为最多 40 个字符(如果可能)。