使用 R Markdown 在 Tufte 输出中渲染 R 脚本 [英] Render R Script in Tufte output with R Markdown

查看:71
本文介绍了使用 R Markdown 在 Tufte 输出中渲染 R 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速问题:如何使用 tufte 样式使用 R Markdown 渲染 R 脚本(因此,一组函数)?

Quick question: how can I render an R Script (so, a set of function) with R Markdown, using the tufte style?

假设 "myscript.R" 是我的代码块所在的文件.

Let's say that "myscript.R" is the file in which I have my chunk of code.

目前我使用这种语法来生成一个 pdf:

Currently I use this syntax to generate a pdf:

rmarkdown::render("myscript.r", "pdf_document")

如何将信息传递给此字符串以根据 tufte 样式格式化 pdf 文档?

How can I pass to this string the info to format the pdf document according to the tufte style?

推荐答案

您可以将 tufte 样式的 Rmarkdown 文档作为模板,然后在您的 Rscript.R 中获取源代码,以便从控制台转换为 PDF.

You could have the tufte style Rmarkdown document as a template, and then source in your Rscript.R in order to PDF from the console.

tufte.Rmd 那是 Rstudio Tufte 模板.

tufte.Rmd That was Rstudio Tufte Template.

---
title: "A Tufte Handout Example"
runningheader: "Tufte Handout with R Markdown" # only for pdf output
subtitle: "An implementation in R Markdown" # only for html output
author: "test"
date: "`r Sys.Date()`"
output:
  tufte::tufte_html: default
  tufte::tufte_handout:
    citation_package: natbib
    latex_engine: xelatex
  tufte::tufte_book:
    citation_package: natbib
    latex_engine: xelatex
bibliography: skeleton.bib
link-citations: yes
---


```{r, results='asis'}
source('myscript.R')
```

myscript.R

library(knitr)
print(kable(mtcars))

并且将这两个文件放在同一个目录中,我可以运行

And with both of these files in the same exact directory, I can run the

rmarkdown::render("tufte.Rmd", output_format = "pdf_document")

tufte 模板有很多格式,但这是一个简单的例子.

The tufte template has a lot of formatting, but this was a simple example.

这篇关于使用 R Markdown 在 Tufte 输出中渲染 R 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆