knitr

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

Add chunk of code without executing it

给你一囗甜甜゛ 提交于 2019-12-19 15:40:31
问题 In knitr , is there any option that allows code to be inserted without being executed? I only want the code to appear in the document with the same style than other knitr code chunks. I am particularly interested in the options for LaTeX in a .Rnw document. 回答1: Like @Ramnath commented, this can be achieved using the eval = FALSE chunk option. 来源: https://stackoverflow.com/questions/21950622/add-chunk-of-code-without-executing-it

How to use otf-font in ggplot2 graphics?

爱⌒轻易说出口 提交于 2019-12-19 10:48:14
问题 I want to use an otf-font in my ggplot2 graphics. I'm using Mac OS X 10.9. I found http://goo.gl/dFqJhV But the experimental part won't work for me. http://goo.gl/rNmIRR doesn't work either because I got lot's of errors compiling the branch. The mentioned branch seems to be too old. The solution with cairo_pdf() (http://goo.gl/LcYFS6) does work but not for me, because I want to embed the graphics into a knitr file with output pdf and/or html. 回答1: You can try the showtext package combined

unable to send R code from a knitr document to SublimeREPL

若如初见. 提交于 2019-12-19 10:26:31
问题 I'm using Sublime 3, and I have a very simple question. SublimeREPL is working perfectly with R files, and Sublime compiles perfectly the knitr files (using LaTeXing) But if I want to send R code from a knitr file (.Rnw) I get the following error: Cannot find REPL for 'tex.latex.knitr.ing' (I'm using Ubuntu 14.04 by the way) Any ideas? 回答1: Ok, so someone solved it here: https://github.com/wuub/SublimeREPL/issues/165#issuecomment-57658359 Just in case someone has the same problem: this file

Insert images using knitr::include_graphics in a for loop

浪子不回头ぞ 提交于 2019-12-19 09:48:25
问题 ```{r} knitr::include_graphics(path = "~/Desktop/R/Files/apple.jpg/") ``` The above code chunk works fine. However, when I create a for loop, knitr::include_graphics does not appear to be working. ```{r} fruits <- c("apple", "banana", "grape") for(i in fruits){ knitr::include_graphics(path = paste("~/Desktop/R/Files/", i, ".jpg", sep = "")) } ``` 回答1: This is a known issue knitr include_graphics doesn't work in loop #1260. A workaround is to generate paths to images within a for loop and cat

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

Getting ggvis::export_png() working

被刻印的时光 ゝ 提交于 2019-12-19 07:53:51
问题 Goal Export a ggvis figure as a PNG file (for inclusion in an .Rmd document). Problem I know essentially nothing about Node.js, other than that it is great and I should know more. I get as far as: library(ggvis) mtcars %>% ggvis(~mpg, ~wt) %>% export_png() Writing to file plot.png Guessing layer_points() module.js:340 throw err; ^ Error: Cannot find module 'd3' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364

Getting ggvis::export_png() working

对着背影说爱祢 提交于 2019-12-19 07:53:06
问题 Goal Export a ggvis figure as a PNG file (for inclusion in an .Rmd document). Problem I know essentially nothing about Node.js, other than that it is great and I should know more. I get as far as: library(ggvis) mtcars %>% ggvis(~mpg, ~wt) %>% export_png() Writing to file plot.png Guessing layer_points() module.js:340 throw err; ^ Error: Cannot find module 'd3' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364

Issue with Pander+Knitr: Error when using pander.list

不羁的心 提交于 2019-12-19 07:48:52
问题 Another reproducible error with pander (+ knitr): When I try to pander a list, I cannot create a PDF File - it seems to occur when a table or data.frame is put inside the list. If only vectors are in the list, the PDF compiles but looks ugly. I use pander 0.5.1, knitr 1.7, R version 3.1.1, Miktex + RStudio on Windows. Doesn't work: ```{r, eval=FALSE} pander(list(cor=cor(cars) ) ) ``` Error: output file: Preview-e905ccd5f1a.knit.md ! Undefined control sequence. l.246 \textbf{cars}: {[}1{]} ``