r-markdown

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

一笑奈何 提交于 2019-12-20 03:23:46
问题 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

Bookdown add URL as footnote

匆匆过客 提交于 2019-12-20 03:16:33
问题 I am having problems getting correct pdf output of figure legends that contain a url. It works as bookdown::gitbook but not as bookdown::pdf_book Here is an example: --- output: bookdown::pdf_book --- ## Reference with URL doesn't work In this experiment, we will use a [spectrophotometer] (https://en.wikipedia.org/wiki/Spectrophotometry) to measure the absorption of light of different wavelength by colored solutions. (ref:spectrum) [Spectrum of light. V, violet; B, blue; G, green Y, yellow; O

Rstudio pdf knit fails with “Environment Shaded undefined” error

雨燕双飞 提交于 2019-12-20 02:46:12
问题 When trying to knit a PDF using a template from package rticles output: rticles::acm_article I get the following error: ! LaTeX Error: Environment Shaded undefined. See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ... l.76 \begin{Shaded} This appears to only happen when I include code chunks within the output document. Reproducible example : You will need to start a new R Markdown document using the New Document -> From Template -> Association for

Automating the generation of preformated text in Rmarkdown using R

扶醉桌前 提交于 2019-12-20 01:58:17
问题 I'm creating a document in which I repeat the same formatting multiple times. So I want to automate the process using the for loop in R. Here's a simple example. Assume, I have an R code that computes some information for all cut values in ggplot2::diamonds dataset, which I want then to print in my document in five separate sections (one section per cut): library(knitr); library(data.table) dt <- data.table(ggplot2::diamonds) for (cutX in unique(dt$cut)) { dtCutX <- dt[cut==cutX, lapply(.SD

Copy and paste an image from clipboard to Rmarkdown / .rmd code

夙愿已清 提交于 2019-12-19 22:27:34
问题 How can I copy an image to the clipboard and then directly insert/paste it in an .Rmd file? See also here: https://github.com/rstudio/rstudio/issues/4038 Spoiler: I wanted to post this question and then decided to give it a shot myself. (It is a bit weird asking a question and answering it yourself, but when i read this i felt motivated enough :) https://stackoverflow.com/help/self-answer) So far i got a workaround via python (see answer below), but it works and saved me quite some silly work

Can't use Rcpp engine in R Markdown

微笑、不失礼 提交于 2019-12-19 17:46:20
问题 I tried to Knit HTML the following Rmd file: --- title: "Untitled" author: "Florian Privé" date: "12 septembre 2016" output: html_document --- ```{r fibCpp, engine='Rcpp'} #include <Rcpp.h> // [[Rcpp::export]] int fibonacci(const int x) { if (x == 0 || x == 1) return(x); return (fibonacci(x - 1)) + fibonacci(x - 2); } ``` I got the following error: Building shared library for Rcpp code chunk... Warning message: l'exécution de la commande 'make -f "C:/PROGRA~1/R/R-33~1.1/etc/x64/Makeconf" -f

Run R interactively from Rscript

浪子不回头ぞ 提交于 2019-12-19 17:31:10
问题 I'm trying to start a shiny app or an interactive .Rmd document from an Rscript. However, all I get is a message Listening on http://127.0.0.1:... I believe this is because R is running in interactive mode (another post about this). How can I write the proper Rscript so that either of the following would work? My script #!/usr/bin/Rscript ## This library(shiny) runApp(appDir = "../app") ## Or this ## rmarkdown::run("Main.Rmd") 回答1: If I understand your question correctly, I was able to

Equation Numbering in Rmarkdown - For Export to Word

天涯浪子 提交于 2019-12-19 09:18:06
问题 When kniting a Rmarkdown file to MS Word, is there a way to have equations labled with a number that is flushed to the right? For example: When typing this in Rmarkdown: $$a + b = c$$ I need it to end up in Word as: a + b = c (1) I saw the code below somewhere else, but it does not seem to work when kniting to Word... \begin{equation} \label{eq-abc} a + b = c \end{equation} Thanks! 回答1: @Sholom's comment regarding pandoc-crossref inspired me to have a read, I was not previously aware of it

Plot margins in RMarkdown/knitr

大城市里の小女人 提交于 2019-12-19 09:08:50
问题 Within RStudio my plots look perfect, but when I generate HTML via the "knit HTML" button my margins are being cut off. I am using the base graphics package to create a simple barplot. I have a large lower margin to accommodate vertical labels across the x-axis, and a wide left margin to keep the y-axis title to the left of some large numbers, e.g.: ```{r set-graph-options} par(mar = c(12, 6, 4, 2) + 0.1, mgp = c(4, 1, 0), las = 2) ``` Both the x-axis and y-axis labels/titles are affected;

Change paper size and orientation in an rmarkdown pdf

爷,独闯天下 提交于 2019-12-19 08:14:31
问题 I'd like to create a PDF using rmarkdown that is A3 (or 11x17, ideally) and in landscape orientation. I can get it to do one or the other by specifying options in the YAML header, but not both at the same time. Here's my best attempt - the classoption values each work individually, but not together: --- title: "Test" output: pdf_document: toc: true number_sections: true documentclass: article classoption: landscape a3paper --- This question is related, but doesn't have the answer in this case