knitr

Loops in Rmarkdown: How to make an in-text figure reference? Figure captions?

老子叫甜甜 提交于 2019-12-07 12:32:07
问题 {r setup, include=FALSE, message=FALSE, results="hide"} knitr::opts_chunk$set(echo = TRUE) library(knitr) library(kfigr) library(dplyr) library(png) library(grid) library(pander) library(ggplot2) Question Loops in rmarkdown: in-text figure reference? figure captions? Goal Use a for loop to create sections with text, in-text results, and multiple figure references with associated figure captions in the figure list. The figure references/numbering should be seemless with figures numbered before

R code in LaTeX in YAML before_body include

流过昼夜 提交于 2019-12-07 12:08:55
问题 I have a LaTeX section that I put at the top of my knitr generated PDF document. I achieved this by using the YAML options output: pdf_document: includes: before_body: file.tex file.tex contains code like this \textsf{Reporting: `r 2+2`} but this doesn't work. Is there another way that I can get this value? Passing in a parameter is fine if that's possible. Thanks! 回答1: You have to knit file.tex . I suggest you rename file.tex , e.g., to file.Rnw , and in your main R Markdown document: ```{r,

Using R markdown and knitr: Possible to get R objects interpreted in YAML

霸气de小男生 提交于 2019-12-07 11:57:17
问题 I am using knitr , R markdown , and a custom LaTeX file to write a manuscript. The abstract is set as part of the YAML frontmatter. This works great, except that the results that I would like to include in the abstract are generated later in the document. Having the abstract in the YAML makes some sense to me and I would prefer to keep it this way. Any thoughts on a way to have the abstract take advantage of calculations that happen later in the document? A brief example: --- title: 'How do I

Internationalization R knitr Figure caption label

风格不统一 提交于 2019-12-07 11:57:07
问题 I want to generate a Latex document with knitr, but it does not allow me to change the label for the figure into my language. The code: ```{r rstudio, echo = FALSE, fig.cap = "RStudio IDE", fig.margin = T} plot(pressure) ``` This generates: However I want the caption label to read Figura: (portuguese) instead of Figure: . I added the variable lang: pt-br , which corrects for when I call it with \@ref(fig:rstudio) , but does not fixes the figure label. How to change the caption label in

How to save and edit the content of a kable print?

落爺英雄遲暮 提交于 2019-12-07 10:39:16
问题 This is a follow-up to how to export a dataframe to latex with some minimal formatting? Consider this working example ```{r table, results='asis'} library(knitr) library(kableExtra) library(magrittr) dataframe <- data.frame(mytext1 = c('HELLO', 'WORLD'), mytext2 = c('HELLO', 'AGAIN'), value1 = c(1,2), value2 = c(1,2)) piper <- dataframe %>% kable(format = 'latex', booktabs = TRUE) %>% add_header_above(header = c("Text" = 2, "Values" = 2)) ``` which gives \begin{tabular}{llrr} \toprule

If-Else Statement in knitr/Sweave using R variable as conditional (Part 2)

∥☆過路亽.° 提交于 2019-12-07 09:39:34
问题 I am extending a question I posted here: If-Else Statement in knitr/Sweave using R variable as conditional I would like to use an if-else syntax in LaTeX so that, depending on the value of an R variable (say x), one of two LaTeX text paragraphs are output. If x>0, then the LaTeX paragraph has a figure and a table. However, if x<0, then the LaTeX paragraph has just a figure (and no table). I have a MWE that works and is based on the checked answer at the previous post: \documentclass[12pt

Scaling plotly figures in knitr Latex document

流过昼夜 提交于 2019-12-07 08:08:58
问题 I'm trying to include a plotly chart into a Latex document with knitr. Since knitr includes the webshot package this works well. But if I want to resize my figure for the latex output, the figure environment gets bigger but the plotly chart is not scalled to the manually set figure width and height. Specifing the webshot options like recommend here, did not work neither. Scaling a ggplot chart works well, but how can I get the same results for the plotly chart? \documentclass{article}

Render code for google chart in rmarkdown Rmd

醉酒当歌 提交于 2019-12-07 05:49:43
问题 Google has some nifty charts. I'm sure there's nice R wrapper packages to do what I want but I want to learn how to include a google chart myself as it will likely be more flexible than an R wrapper for including a google chart. Below is an .Rmd that has a donut function to produce the donut from Google chart gallery. The function outputs a code as expected seen below but to actually knit this results in the following pandoc conversion error. How do I include the google chart code properly in

sourcing References in rmarkdown: workaround

本秂侑毒 提交于 2019-12-07 05:24:01
问题 I am working with markdonw v2, the rmarkdown package. Throughout the .Rmd file, I create links to websites or images [Link1][pathLink1] ![Image1][pathImage1] then, at the end of the document I give the references [pathLink1]:http://website.com/linkes/Link1.md ![pathImage1]:./images_rmd/ There are other reports that talk about the same citation and use same images in different contexts. I would like to create a separate file containing all the links and path difinitions, so that I could simply

Update posts using knit2wp

醉酒当歌 提交于 2019-12-07 05:02:19
问题 I have been able to successfully post to WordPress using knit2wp, even with images. Even possessing such talent, I am not infallible. Indeed, even the above took some work. I'd like to be able to update posts later. Apparently, the RWordPress package allows for deletion of posts, but that doesn't help much if one cannot read the metadata of a post, delete it, post a new post, and update the metadata … and I do not offhand see an option or function to just update a post. Any and all