knitr

Make Scrollbar appear in RMarkdown code chunks (html view)

蓝咒 提交于 2019-12-09 11:20:28
问题 I am making an RMarkdown document using RStudio and knitr. I want my code chunks to print without wrapping text on the html file I create. Is there an option I am missing that stops text wrapping of code? So far I have only found questions about how to remove scrollbars, making me think that maybe something has changed recently. (RStudio Version 0.99.892, R Version 3.2.2) Thanks! Simple example RMarkdown document. (The setup section is the default): --- title: "Stop looking bad RMarkdown!"

R knitr markown: Setting HTML page width

我怕爱的太早我们不能终老 提交于 2019-12-09 10:41:51
问题 I am using knitr to create a HTML webpage. The default setting seems to be 800px but I need a larger page size of 1100px body { max-width: 800px; margin: auto; padding: 1em; line-height: 20px ; } I have tried: library("markdown") library("knitr") knit2html("test.Rmd",options = c(width=1100)) But this still gives me the smaller page size of 800px How can I set the code for the HTML page width? 回答1: Add a css element to your document, e.g. --- title: "test" output: html_document: css: "test.css

R markdown PDF: Temporarily hide spoiler code for quiz takers

℡╲_俬逩灬. 提交于 2019-12-09 10:08:54
问题 I am using R markdown to create a PDF R course. I want to insert a quiz like the following: --- output: pdf_document --- What is the class of the following R object? 1. `pi` ```{r} class(pi) ``` Which, as expected, creates a PDF with this content: However, I would like the reader to not have such an easy access to the answer. These are the ideas I've had so far to achieve this: Paint the answer and code white, so the reader would have to select the text to see the answer; Include a tooltip

Sweave Cache packages

廉价感情. 提交于 2019-12-09 05:21:41
问题 I am trying to sweave a report and my problem is that every time i compile R loads the packages I use in the Report (like ggplot2, MASS, cubature..). This is very time consuming. Is there a way to chache the packages? I found cacheSweave but it does not work. This is the chunk i added in the sweave file: <<cacheSweave, eval=TRUE, echo=FALSE, term=FALSE, cache=TRUE>>= library(cacheSweave) lapply(c("ghyp","MASS","nloptr","cubature","ggplot2"), require, character.only=T) @ Thanks 回答1: Since you

Creating a latex table from ftable object in R

£可爱£侵袭症+ 提交于 2019-12-09 04:31:16
问题 Let me create some data before I ask my question. my.data <- data.frame(A = sample(seq(1,100,by=5),10,replace=TRUE),W = rnorm(10),X =sample(1:10),Y = sample(c("yes", "no"), 10, replace = TRUE),Z=sample(c('a','b','c','d'),10,replace=TRUE)) attach(my.data) my.d <- xtabs(W~Z+Y+A);my.d table.data <- ftable(my.d) result1 <- round(table.data,2) result1 looks like .. A 6 11 16 26 71 76 86 91 Z Y a no 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 yes 0.00 0.56 0.00 0.00 0.00 0.79 0.00 0.01 b no 0.61 0.00

Do not open RStudio internal browser after knitting

喜欢而已 提交于 2019-12-09 02:20:05
问题 I'm working on a presentation in RStudio using rmarkdown and revealjs template. Since it's a work in progress, I often knit the .Rmd file to see the changes. The problem is, each time I press "Knit" button (or use a hotkey), an internal browser window pops up. I don't need it, really, because 1) it displays the presentation incorrectly and 2) I already have the .html file open in my system browser and I simply refresh the page. Is there any way to suppress the default RStudio behaviour?

how to get figure floated / surrounded by text etc. in R markdown?

妖精的绣舞 提交于 2019-12-09 01:36:30
问题 I am currently writing some reports with LaTeX. Due to most of my analysis is made with R, I switched to Rmarkdown, which I am very happy with so far, except one thing, namely when it comes to include figures in the pdf output. Some of my plots are floating, so they are surrounded by text and the other kinds of output, put some other of my figures take a whole page in the pdf document, although they are not that big. And I have absolutely no clue why it is like that. Does anyone know that

how do you print table in knitr

人走茶凉 提交于 2019-12-08 23:27:40
问题 I am trying to us knitr to print data frame in table format using xtable : ```{r xtable,fig.width=10, fig.height=8, message=FALSE, results = 'asis', echo=FALSE, warning=FALSE, fig.cap='long caption', fig.scap='short',tidy=FALSE} print(xtable(d),format="markdown") ``` This is the data frame d : d <- structure(list(Hostname = structure(c(8L, 8L, 9L, 5L, 6L, 7L, 1L, 2L, 3L, 4L), .Label = c("db01", "db02", "farm01", "farm02", "tom01", "tom02", "tom03", "web01", "web03"), class = "factor"), Date =

Using apaTables or apaStyles packages with knitr

人走茶凉 提交于 2019-12-08 19:32:25
Problem Social scientists format tables and documents with APA style . There are packages like stargazer and xtable (here is an extensive list ) that provide clean table formatting for those using latex and knitr . However , these packages do not conform to APA style rules in all cases. Building and formatting tables from scratch is time consuming. Fortunately, there are two R packages for creating tables and documents compliant with APA style guidelines: apaStyle and apaTables . Unfortunately, both packages only output to MS Word. Questions Is there a way to use APAStyle and APATables so that

Pass underscore as inline code to knitR

谁说胖子不能爱 提交于 2019-12-08 18:31:32
I'm using knitR to generate a document. Some of the variable names have underscores that I can't change. Anyway to still insert these as normal text? Basic example: \documentclass{article} \begin{document} <<>>= data.df = data.frame(var_name_1=c(0,1),var_name_2=c(1,2)) @ I want to be able to print \Sexpr{(names(data.df)[1])} and \Sexpr{(names(data.df)[2])} normally. \end{document} Tkanks in advance for your assistance. A suitable work around is to define the function rep_ in the code block. rep_ just looks for the underscore and places a "\" before it. \documentclass{article} \begin{document}