knitr

How to print htmlwidgets to HTML result inside a function?

邮差的信 提交于 2019-12-05 22:03:52
--- title: "Untitled" output: html_document --- ```{r setup, include=FALSE} library(DT) xsx = function(){ print(getOption("viewer")) print(datatable(data.frame(d =1))) 1 } xsx() ``` Inside xsx() function, DT widgets will not be rendered in HTML result. How can I get widgets print inside a function? 来源: https://stackoverflow.com/questions/35567124/how-to-print-htmlwidgets-to-html-result-inside-a-function

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

老子叫甜甜 提交于 2019-12-05 21:34:33
{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 and after these new sections. Note: The figures referenced in the for loop are generated earlier in

Accessing YAML parameters as macros within external LaTeX files

强颜欢笑 提交于 2019-12-05 21:24:33
问题 I'm looking for ways to add variables (or LaTeX macros) to the YAML header or soon after such that they can be used in external .tex files that are a part of my (modularised) report. My .rmd file --- output: pdf_document: latex_engine: xelatex includes: before_body: some.tex params: cat: "Felix" numb: 14 --- # chapter Oh my \textbf{`r params$cat`}. $x = `r 2*params$numb`^2$ <!-- Trying again to get the parameter --> \input{some.tex} My some.tex file: `r params\$cat` Output Hoped-for output I

Increment section numbers in PDF output

雨燕双飞 提交于 2019-12-05 21:22:17
I'm trying to increment the section headers in my rMarkdown (PDF output) file by 1. Instead of # First resulting in 1 First , I'd like 2 First. I found a way to define the offset in html_output using the following syntax, but it doesn't work for pdf_output. --- title: "Untitled" author: "author" date: "date" output: html_document: toc: true pandoc_args: [ "--number-sections", "--number-offset=1" ] --- # First Header # First SubHeader This results in 2 First Header 2.1 First Subheader However, this syntax does not work for PDF documents: --- title: "Untitled" author: "author" date: "date"

non-evaluated vignettes with knitr::rmarkdown_notangle

六月ゝ 毕业季﹏ 提交于 2019-12-05 18:49:52
问题 The knitr package has relatively recently added new notangle vignette engines, such as knitr::rmarkdown_notangle , that allow disabling of evaluation of vignette chunks. The general process of using knitr for vignettes is described here, while the specific notangle functionality is described in an answer to this question. My problem is that I can't get this to work. I can get it to pass R CMD build by including the .html output in the vignettes directory (I also put a copy in inst/doc ), but

knitr - How to align code and plot side by side

家住魔仙堡 提交于 2019-12-05 18:11:40
问题 is there a simple way (e.g., via a chunk option) to get a chunk's source code and the plot it produces side by side, as on page 8 (among others) of this document? I tried using out.width="0.5\\textwidth", fig.align='right' , which makes the plot correctly occupy only half the page and be aligned to the right, but the source code is displayed on top of it, which is the normal behaviour. I would like to have it on the left side of the plot. Thanks Sample code: <<someplot, out.width="0.5\

how to add grid to table with pander?

梦想与她 提交于 2019-12-05 16:37:27
I am working with R, knitr and pander, and I can't find the option that would allow me to print a grid on a table with pander. I tried : pander(tableToPrint, style='grid') but it doesn't do anything, neither with this option or with 'multiline', 'rmarkdown'... I always get an horizontal line, then the column names, another horizontal line, all my data and an horizontal line. I would like to have an horizontal line between every line. Another option would be to alternate row colors. scoa There is an old answer that gives the trick to do that in latex, but in needs a bit of adaptation to pandoc.

Adjusting sankey plot in tabbed section

£可爱£侵袭症+ 提交于 2019-12-05 15:44:39
问题 In the r-markdown document given below, I use tabbed sections to display sankey plots. However, when a sankey plot is in a tab other than the first, adjusting (using htmlwidgets::onRender function) does not work. Does anybody know a way to overcome that problem? Related question: How to control node labels in Sankey diagram --- title: "Untitled" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = FALSE) library(networkD3) library(htmlwidgets) nodes <- data.frame

Add tex distribution to PATH for R studio

笑着哭i 提交于 2019-12-05 15:05:17
I have recently begun using knitr with Rstudio. I ran into the "No tex installation detected. Please install TeX before compiling." error in both my Ubuntu and windows OS's. After some research I was able to amend the issue in Ubuntu by adding the directory of my tex installation to PATH . I did this by including the following line in Renviron.site PATH=/usr/local/texlive/2013/bin:${PATH} However, the issue remains for my windows installation. I was unable to find the Renviron.site file, so I created one in the same directory of Renviron, and added the location of my tex installation in

R Notebook - code chunk gets separated in preview

谁说我不能喝 提交于 2019-12-05 14:22:18
I am using R notebook to preview the file. Even though all the code is in one chunk, a line gets separated into two. Would you please tell me how I can resolve this? As you can see all the code is in one chunk. However, when I run this chunk, it gets separated into two. I am not sure if it matters but here is the code I am running. library(MASS) par(mfrow=c(3,1)) hist(galaxies, breaks=500) hist(galaxies, breaks=100) hist(galaxies, breaks=50) Also here are the versions of R and RStudio. I an new to R so I am not sure what is causing this. If you need any other information, please let me know.