knitr

html_notebook ignores global chunk options

一笑奈何 提交于 2019-12-10 17:32:58
问题 Is there a way to use global chunk options in html_notebooks? This html_document only shows the title (as desired in this MWE): --- title: "Test" output: html_document --- ```{r setup, echo=FALSE} library(knitr) opts_chunk$set(echo=FALSE, results='hide', fig.keep='none') ``` ```{r} 1+1 plot(1:5, 1:5) ``` However, the very same document as an html_notebook shows all code chunks and output (the global chunk options are ignored): --- title: "Test" output: html_notebook --- ```{r setup, echo

How to wrap text around plots in R Markdown?

扶醉桌前 提交于 2019-12-10 17:23:36
问题 Currently the default for R Markdown in R is to have one line of text in line with the plot but this looks very awkward and I would like to save space by having the text wrap around the plot (plot aligned left, with text wrapping on the right). 来源: https://stackoverflow.com/questions/40652012/how-to-wrap-text-around-plots-in-r-markdown

Splitting a plot call over multiple chunks

不羁岁月 提交于 2019-12-10 17:13:11
问题 I'm writing an explanation of a plot where I'll basically create the plot in a first chunk, then describe that output, and add an axis in a second chunk. However, it seems each chunk forces a new plotting environment, so we get an error when trying to run a chunk with axis alone. Observe: --- output: html_document --- ```{r first} plot(1:10, 1:10, xaxt = "n") ``` Look, no x axis! ```{r second} axis(side = 1, at = 1:10) ``` Error in axis(side = 1, at = 1:10) : plot.new has not been called yet

R/shiny + mathjax, not rendering math

喜欢而已 提交于 2019-12-10 16:59:34
问题 I'm having odd behavior with MathJax and shiny . I've modified the 01_hello example from the shiny package to include a .Rmd file via includeMarkdown() . All I modified was ui.R to be as follows: # Show a plot of the generated distribution mainPanel( plotOutput("distPlot"), includeMarkdown("mathjax-test.Rmd") ) The contents of my test file ( mathjax-test.Rmd ) are like so: ## mathjax test Document used as is in .Rmd format. Here's an inline equation with dollar signs: $a + b = c$ Here's an

Root directory for python chunk in knitr?

让人想犯罪 __ 提交于 2019-12-10 16:58:18
问题 I hope this isn't as simple as it feels. I've got a basic directory set up of: root --> Paper --> Code for a paper I'm writing. I want to call a Python script in the Code directory from my knitr document in the Paper directory (something like this, but with Python instead of R). So it would be something like this: Python script testit.py ## @knitr testit import os print os.getcwd() knitr document test.Rnw saved in the Code directory: \documentclass{article} \begin{document} <<setup,echo=FALSE

Is there a way to include child Rmd files from a different directory

拥有回忆 提交于 2019-12-10 16:34:31
问题 I have a master markdown file, e.g., Parent.Rmd, and a number of child documents being included with: ```{r child="introduction.Rmd", echo=FALSE} ``` ```{r child="chapter2.Rmd", echo=FALSE} ``` It seems that I should be able to do: ```{r child="Rmd/introduction.Rmd", echo=FALSE} ``` to pull the same file from a sub directory named 'Rmd' but knitr can't open the connection. I've also tried to use: `knitr::opts_chunk$set(child.path='Rmd')` but the chunk code ignores it. Is there another way? My

Function to sanitize strings for LaTeX compilation?

时间秒杀一切 提交于 2019-12-10 16:13:00
问题 While xtable() has a sanitize.text.function argument which allows to sanitize strings with special charaters to stop LaTeX compilation from breaking in Sweave/knitr documents, the package does not export the function to the userspace. How can I sanitize strings like asdf_text outside of the xtable context, so as to have it transformed to something like asdf\_text ? (If possible I would prefer a small, self-contained solution.) 回答1: Unless I misunderstand your question, I think you've

knitr: knitting chunks with parsing errors

柔情痞子 提交于 2019-12-10 16:01:22
问题 Is it possible to knit chunks with parsing errors? I want to produce a document explaining some different types of errors one can find while coding in R, but it seems that I can't knit a chunk with parsing error, even with error = TRUE . For example, this chunk works fine and it shows the error messages: ```{r sum character, error = TRUE} "1" + "2" ``` However, this chunk doesn't: ```{r missing parenthesis, error = TRUE} f <- function(x){ z <- sum(x # y <- x + 1 return(x + y + z) } ``` It

Problems cross referencing in LaTex with knitr and xtable

ε祈祈猫儿з 提交于 2019-12-10 15:45:33
问题 I am currently working with R Studio to produce PDF documents with R/knitr in LaTex. Within these documents I want to present part of my results in tables that I want to refer to in the text. I produce these tables using the xtable package within R and it is working perfectly and giving me the right tables. So far so good but when it come to referencing I ran into some troubles. At the moment the resulting PDF output refers to the section in which the table lies. I searched around in some

add caption to flextable in docx

牧云@^-^@ 提交于 2019-12-10 15:37:11
问题 How could one add a caption to a flextable rendered to docx? EDIT: The aim is to produce a proper caption which can be referenced within the document to produce a list of tables and inline references. iris.t <- iris[1:5,] %>% regulartable() %>% style(pr_c = officer::fp_cell(vertical.align = "bottom", border.bottom = officer::fp_border(width = 2)), part = "header") %>% rotate(j = names(iris)[-c(1:2)], rotation = "tbrl", part = "header", align = "bottom") %>% height(height = max(dim_pretty(.,