R code remains inside Beamer

Here is my MWE code.

\documentclass{beamer} \begin{document} <<setup, include=FALSE>>= # smaller font size for chunks opts_chunk$set(size = 'footnotesize') options(width=60) @ \begin{frame}[fragile] \frametitle{Test1} <<boring-random>>= y <- c(5, 7, 15, 17, 17, 19) Trt <- gl(n = 3, k = 2, length = 3 * 2, labels = paste("Trt", 1:3, sep = ""), ordered = FALSE) Data <- data.frame(Trt, y) Fit1 <- aov(formula = y ~ Trt, data = Data, contrasts = list(Trt = "contr.sum")) ANOVA1 <- anova(Fit1) Coeffs1 <- coefficients(Fit1) @ \end{frame} \end{document} 

enter image description here

I try my best to keep the R-code in the Beamer frame. I wonder what an effective way to manage R-block codes is to keep them inside the Beamer framework. Thanks

+7
source share
1 answer

The best approach is to disable the tidy option on tidy=FALSE and manually break your lines.

 <<boring-random, tidy=FALSE>>= y <- c(5, 7, 15, 17, 17, 19) Trt <- gl(n = 3, k = 2, length = 3 * 2, labels = paste("Trt", 1:3, sep = ""), ordered = FALSE) Data <- data.frame(Trt, y) Fit1 <- aov(formula = y ~ Trt, data = Data, contrasts = list(Trt = "contr.sum")) ANOVA1 <- anova(Fit1) Coeffs1 <- coefficients(Fit1) @ 

It will always work. Another way is to set a smaller width in options() ( knitr FAQ 8 ), and you probably need to try several times for the ideal width . In your case, 60 is apparently too large.

+5
source

All Articles