knitr

Create tables with conditional formatting with RMarkdown + knitr

浪子不回头ぞ 提交于 2019-12-28 11:46:06
问题 I have a data frame and I want to output this in an HTML file through knitr and RMarkdown as a table with conditional formatting. Example: n <- data.frame(x = c(1,1,1,1,1), y = c(0,1,0,1,0)) > n x y 1 1 0 2 1 1 3 1 0 4 1 1 5 1 0 I want rows with different values of x and y to be highlighted. So in this case, that would be rows 1, 3 and 5. Would be nice if the output in the HTML file would be an HTML table, but failing that an image would be fine as well. 回答1: I always wanted to extend pandoc

How to avoid using round() in every \Sexpr{}?

丶灬走出姿态 提交于 2019-12-28 08:10:19
问题 Is there a way to avoid the function round() when using Sweave/knitr? It's really annoying to write round(,2) in every \Sexpr{} . I would like to have two decimal places through the whole document. Thanks for your help Macs 回答1: If you have read the motivation of the knitr package, you probably know I'm the person who hates round() inside \Sexpr{} most. I suggested this to R core long time ago for Sweave but it was ignored, so I started my own package. Although the answer by Josh O'Brien is

Print a list of dynamically-sized plots in knitr

我的未来我决定 提交于 2019-12-28 06:46:32
问题 I want to be able to print out non-predetermined list of plots in knitr. I am able to do that, but there are a few wrinkles left to iron out. Namely: 1) How do you suppress the list indices (like [[2]]) on each page that precede each plot? Using echo=FALSE doesn't do anything. 2) Is it possible to set the size for each plot as they are rendered? I've tried setting a size variable outside of the chunk, but that only lets me use one value and not a different value per plot. I'm asking this as

R Knitr PDF: Is there a posssibility to automatically save PDF reports (generated from .Rmd) through a loop?

混江龙づ霸主 提交于 2019-12-28 05:47:44
问题 I would like to create a loop, which allows me to automatically save PDF reports, which were generated from a .Rmd file. For instance, if a variable "ID" has 10 rows, I would like R to automatically save me 10 reports, into a specific directory. These reports shall vary based on the ID selected. A previous post (Using loops with knitr to produce multiple pdf reports... need a little help to get me over the hump) has dealt with the creation of multiple pdf reports generated from .Rnw files. I

Caption above figure using knitr (LaTeX/PDF)

北慕城南 提交于 2019-12-28 04:15:13
问题 I would like to place the caption above the figure using knitr in texmaker. I know that this question has already been asked, and I understand that the solution suggested so far is to use: \begin{figure} \caption{This is a caption above the figure} <<a-plot, echo=FALSE>>= plot(1) @ \end{figure} But in this way I cannot show the code (since echo=FALSE ). And if I choose instead echo=TRUE , what I get is the caption, then the codes, and then the graph, which is also not what I want. What I

how to create a loop that includes both a code chunk and text with knitr in R

大兔子大兔子 提交于 2019-12-28 01:55:11
问题 I am trying to figure out how to create a loop that inserts some text into the rmarkdown file, and then produces the graph or table that corresponds to that header. The following is how I picture it working: for(i in 1:max(month)){ ### `r month.name[i]` Air quaility ```{r, echo=FALSE} plot(airquality[airquality$Month == 5,]) ``` } This ofcourse just prints the for loop as text, if i surround the for loop with r`` I would just get an error. I want the code to produce an rmd file that looks

In `knitr` how can I test for if the output will be PDF or word?

不羁岁月 提交于 2019-12-27 14:33:42
问题 I would like to include specific content based on which format is being created. In this specific example, my tables look terrible in MS word output, but great in HTML . I would like to add in some test to leave out the table depending on the output. Here's some pseudocode: output.format <- opts_chunk$get("output") if(output.format != "MS word"){ print(table1) } I'm sure this is not the correct way to use opts_chunk , but this is the limit of my understanding of how knitr works under the hood

In `knitr` how can I test for if the output will be PDF or word?

亡梦爱人 提交于 2019-12-27 14:33:34
问题 I would like to include specific content based on which format is being created. In this specific example, my tables look terrible in MS word output, but great in HTML . I would like to add in some test to leave out the table depending on the output. Here's some pseudocode: output.format <- opts_chunk$get("output") if(output.format != "MS word"){ print(table1) } I'm sure this is not the correct way to use opts_chunk , but this is the limit of my understanding of how knitr works under the hood

Accessing the internet with knitr

血红的双手。 提交于 2019-12-25 14:26:37
问题 When I run some code to draw a map using ggmap, in Rstudio it runs fine. When I run it using knitr it fails with the following error message:- Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") : cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=-40.851253,172.799669&zoom=19&size=%20640x640&scale=%202&maptype=hybrid&sensor=false' Calls: ... eval -> eval -> get_map -> get_googlemap -> download.file In addition: Warning message: In download

Accessing the internet with knitr

狂风中的少年 提交于 2019-12-25 14:26:06
问题 When I run some code to draw a map using ggmap, in Rstudio it runs fine. When I run it using knitr it fails with the following error message:- Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") : cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=-40.851253,172.799669&zoom=19&size=%20640x640&scale=%202&maptype=hybrid&sensor=false' Calls: ... eval -> eval -> get_map -> get_googlemap -> download.file In addition: Warning message: In download