使用现有R会话中的对象运行Sweave或knitr [英] Run Sweave or knitr with objects from existing R session

查看:56
本文介绍了使用现有R会话中的对象运行Sweave或knitr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在当前会话中有一个对象x:

Suppose I have an object x in my current session:

x <- 1

如何在Sweave或knitr文档中使用该对象,而不必显式分配它:

How can I use this object in an Sweave or knitr document, without having to assign it explicitly:

\documentclass{article}
\begin{document}
<<>>=
  print(x)
@
\end{document}

我问的原因是因为我想编写一个R脚本来导入数据,然后使用Sweave模板为每个主题生成报告.

Reason I am asking is because I want to write an R script that imports data and then produces a report for each subject using an Sweave template.

推荐答案

我认为它是可行的.如果您的Sweave文件名为"temp.Rnw",只需运行

I think it just works. If your Sweave file is named "temp.Rnw", just run

> x <- 5
> Sweave("temp.Rnw")

您将不得不担心正确命名结果输出,以免每个报告都被覆盖.

You'll have to worry about naming the resulting output properly so each report doesn't get overwritten.

这篇关于使用现有R会话中的对象运行Sweave或knitr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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