knitr

custom syntax highlighting rmd

折月煮酒 提交于 2019-12-11 11:34:52
问题 I would like to be able to customize the syntax highlighting used with RMarkdown so that I can, for example, draw attention to functions coming from a certain package. I noticed an option mentioned in the knitr NEWS document which says this option can be set via: opts_knit$set(highr.opts = list(markup = cmd_mine)) for .Rnw and .Rhtml documents. However, when I set this option in my .Rmd file (simplified here to messing with the highlight for numerical constants) ```{r setup, include=TRUE} #

object 'C_stri_join' not found - Using knitr in Rstudio

扶醉桌前 提交于 2019-12-11 10:47:00
问题 When using the knit button in Rstudio I get an error object 'C_stri_join' not found . Here is an example: --- title: "Sample Document" output: html_document: toc: true theme: united --- <!-- %\VignetteEngine{knitr::knitr} %\VignetteIndexEntry{Basic test} --> Here we go ```{r} x <- 1 str(x) ``` The error is as follows: Error in stri_c(..., sep = sep, collapse = collapse, ignore_null = TRUE) : object 'C_stri_join' not found Calls: suppressPackageStartupMessages ... evaluate_call -> handle

Use image as table in RMarkdown?

情到浓时终转凉″ 提交于 2019-12-11 10:42:04
问题 I appreciate that what I'm trying to do will sound silly, but please bear with me. I want to insert an existing image (a PNG) of a table into an RMarkdown document that will be turned into a pdf. Is there any way I can do this and have the image treated as a table for numbering purposes? That is, obviously I could do ![A caption for my table](my_table_as_image.png) but the problem is that it will be numbered as e.g. Figure X, not Table Y. I would like it to be named/numbered as a table. Thank

How do you change the font size in RMarkdown for Knitr

空扰寡人 提交于 2019-12-11 10:34:05
问题 I created a Knitr document and I want to adjust the font size for the text that is NOT in the chunks. It currently appears too small and want to increase it. Currently I am just writing a line like this: Example text --------- And that will make it larger but I can't control the font size. This is for an HTML document 回答1: For .Rmd files, you can affect the HTML header size using different numbers of # characters, instead of the alternative underlined form which only gives you H1 and H2 sizes

Compiling multiple PDFs using knitr and texi2dvi

拈花ヽ惹草 提交于 2019-12-11 10:33:48
问题 My goal is to use knitr to produce separate PDFs for data associated with each factor level in a data set. However, I've gotten a variety of errors (included below) and am unable to compile the .tex files that are produced. I've tried trouble shooting with the main SO post on the topic here as well as Yihui's GitHub code here, but I'm still not getting a final product. I suspect there might be other users who are also still struggling to get this right after looking at the listed resources.

fenced code blocks when converting R Markdown to pdf

走远了吗. 提交于 2019-12-11 10:24:30
问题 When I compile an R Markdown document to an HTML document, the non-R code blocks are formatted nicely. But when I compile the following R Markdown document to pdf, the only added code formatting is in the font. There is no shading, fencing, highlighting, etc. --- output: pdf_document --- ``` code ``` I don't want to micromanage the output, I just want to add some common-sense formatting to clearly separate the code from the prose. I'm using TeXShop on a MAc with the engine below. #!/bin/bash

knitr not recognizing r-code chunks

随声附和 提交于 2019-12-11 09:47:24
问题 I am testing knitr in R-Studio (with MacOS 10.10.3) in a Markdown file with the following code chunk: ```{r} summary(cars) ``` The compilation stops with the following message: processing file: Preview-13c324b5a94e.Rmd Warning: namespace 'formatR' is not available and has been replaced by .GlobalEnv when processing object 'silent' Quitting from lines 13-14 (Preview-13c324b5a94e.Rmd) Error in loadNamespace(name) : there is no package called 'evaluate' Calls: <Anonymous> ... tryCatch ->

Save a rmarkdown ioslides presentation as standalone website

a 夏天 提交于 2019-12-11 09:43:49
问题 I would like to save the presentation generated by knitr as a html file. Which I am able to share with people as standalone html file. If I use Run Document button in R studio (server) this generates a file with the .Rmd extension. --- title: "Standalone" author: "MarketRedesign" date: "10-7-2014" output: ioslides_presentation --- ## Slide with R Code and Output ```{r} summary(cars) ``` 回答1: When you press the knit HTML button, a HTML file IS always created by RStudio in the same directory as

Export Graph in R, and also display it in knitr

落爺英雄遲暮 提交于 2019-12-11 09:16:15
问题 I'm using knitr and want my rmd file to generate an eps file in a figures/ folder whenever it's run. I found this question: Export a graph to .eps file with R which does what I want, but doesn't display the charts in the webpage produced by knitr, presumably because the postscript command just routes anything drawn to the file you give it. I would like to display a graph AND save it to the file. Currently my code is something like: ```{r} setEPS() postscript("~/File/Path/To/Figures/Folder

knitr: Overwrite chunk options with hook function

断了今生、忘了曾经 提交于 2019-12-11 08:48:00
问题 Motivated by https://gist.github.com/yihui/2629886#file-knitr-checkpoint-rnw, I want to create a knitr hook that can overwrite certain options of a knitr chunk: \documentclass{article} \begin{document} <<setup>>= knit_hooks$set(checkpoint = function(before, options, envir) { if (!before) { opts_chunk$set(echo = TRUE, include = TRUE) opts_current$set(echo = TRUE, include = TRUE) ## no effect } }) opts_chunk$set(echo = TRUE, include = TRUE, checkpoint = "foobar") @ <<example-a, echo=FALSE>>= x