knitr

Pandoc's environment cslreferences undefined when knitting RMarkdown to PDF in RStudio

ⅰ亾dé卋堺 提交于 2019-12-13 20:41:45
问题 Knitting (in RStudio version 1.2.1335) an RMarkdown file to PDF fails when trying to create citations (for pandoc version 2.8.0.1, and R version 3.6.1). (This does not happen when knitting to HTML, for example.) Here is a small rep. ex. in RMarkdown: --- title: "Rep. Ex. for 'LaTeX Error: Environment cslreferences undefined'" output: pdf_document: default bibliography: report.bib --- ```{r generate-bibtex-file, include=FALSE} knitr::write_bib(file = "report.bib", prefix = "") ``` # Used R

Make NA values in table just blank cells when using cell_spec in kableExtra [duplicate]

社会主义新天地 提交于 2019-12-13 20:25:36
问题 This question already has answers here : Hiding NA's when printing a dataframe in knitr (2 answers) Closed 7 months ago . Following on from a previous question, I am using the cell_spec function from kableExtra to change the background color of cells within a table. How can you remove the NA text and color the background white for the NA cells so that an NA appears just as a blank cell? Below is my example table with the NA cells. In real life there is a dynamic number of columns with various

Where is knitr cached output stored?

折月煮酒 提交于 2019-12-13 17:12:30
问题 In the cache directory, one can use lazyLoad to view the environment at the end of a chunk. But where is the output of the chunk (that will be printed if the document is compiled) stored? 回答1: Use the source! Look at the source code here https://github.com/yihui/knitr/blob/master/R/cache.R You can see that the mechanism is explained here (within the new_cache function) # when cache=3, code output is stored in .[hash], so cache=TRUE won't lose # output as cacheSweave does; for cache=1,2,

R markdown / bookdown - how to switch to rticles?

冷暖自知 提交于 2019-12-13 16:14:49
问题 Input data I prepared an example Rmd file with references to figure, table and equation, setting as an output 'bookdown::pdf_document2'. It compiles without errors to PDF. I placed it on dropbox: https://www.dropbox.com/sh/zmu0a4wq95ywssv/AAD-nHlkDiLknLk2NVR4Xup3a?dl=0 Question Now I wish to set as an output format 'rticles::elsevier_article' How can I do that? Issue When I change output line from: bookdown::pdf_document2 to rticles::elsevier_article I'm receiving an error message. Even if I

accessing global environment objects created in cached chunks Rmarkdown documents

天涯浪子 提交于 2019-12-13 14:50:12
问题 I want to run a R script to run a simulation and cache the results for the Rmarkdown document. I am using Rstudio and try to create an HTML report by using knit HTML Here's a simple example. ```{r test_global_env,cache=TRUE} print(getwd()) source("./test_script.R") ``` ```{r test_global_env_2} print(a) ``` and test_script.R is as follows a<-1 When I change the cache option for the chunk to FALSE , print(a) works. If I set it to TRUE, it works the first time, the second time, I get object 'a'

inline Latex code inside knitr R block

浪尽此生 提交于 2019-12-13 14:46:29
问题 I am looking for a way to put inline latex code into a R code chunk in Knitr. Here is my example code from the knitr example site : \documentclass{article} \begin{document} Example text outside R code here; we know the value of pi is \Sexpr{pi}. <<my-label, echo=FALSE, eval=TRUE>>= set.seed(1213) # for reproducibility x = cumsum(rnorm(100)) m <- mean(x) # mean of x print(m) cat(m) plot(x, type = 'l') # Brownian motion @ \textit{Mean is :} \textbf{\Sexpr{m}} \end{document} For something simple

A Way in Knitr to Copy a Chunk?

走远了吗. 提交于 2019-12-13 13:16:07
问题 Knitr Mavens, Background : Using knitr to report a report with many embedded graphs. In the body of the report, all that's appropriate is the graph, not the code. For example: ```{r graph_XYZ_subset, echo = FALSE, message = TRUE, fig.cap = "Text that explains the graph"} graph.subset <- ggplot() + ... ``` This part works just fine. However, there is a need to display the key parts of the code ( e.g., key statistical analyses and key graph generations)...but in an Addendum . Which leads to

Dynamic LaTeX references in R comment with knitr

白昼怎懂夜的黑 提交于 2019-12-13 11:34:39
问题 I had ask a similar question to this with respect to Sweave ( Dynamic references to figures in a R comment within Sweave document ) and would like to see if anyone as a similar answer when using knitr . The goal is to have the following code chunk <<"example", fig.cap = "some figure", highlight = FALSE>>= # the following code generated Figure \ref{fig:example} plot(1:10, 1:10) @ have be displayed in the resulting .pdf as # the following code generated Figure 1.1 plot(1:10, 1:10) So far I have

Knitr Lyx Problems

眉间皱痕 提交于 2019-12-13 08:28:18
问题 I'm working on getting knitr and LyX re-installed and working on my fresh OS setup. I had it working previously. I installed the latest version of R (3.0.1), Knitr is ver 1.3.3, LyX 2.0.6 including the MiKTex 2.9 distribution, and RStudio 0.97.551 on a Windows 7 Enterprise computer. I can get pdflatex output if I open up Lyx and simply view the tutorial, so the basic system is working. I've tried running old LyX files I had with Knitr, but now they fail. Initially there appeared to be a path

Unset existing scale_fill_discrete in ggplot2 or suppress message for new scale

社会主义新天地 提交于 2019-12-13 07:26:12
问题 I am currently trying to knit an R markdown document to html (or pdf) where in a certain chunck I generate multiple plots. I specify the captions through the fig.cap argument in the chunck options with a vector of the same length as the number of plots. However, for this to work the cunck option message has to be TRUE . The issue starts when a ggplot2 object is generated by a function in the chucnk and I want to apply a new fill with viridis::scale_fill_viridis . Which is fine, but inevitably