简体   繁体   English

有没有办法使用RStudio直接从工作区中编织降价?

[英]Is there a way to knitr markdown straight out of your workspace using RStudio?

I wonder whether I can use knitr markdown to just create a report on the fly with objects stemming from my current workspace. 我想知道我是否可以使用knitr markdown来创建一个动态报告,其中包含源自当前工作空间的对象。 Reproducibility is not the issue here. 再现性不是问题。 I also read this very fine thread here . 我也在这里读了这篇非常好的帖子

But still I get an error message complaining that the particular object could not be found. 但是我仍然收到一条错误消息,抱怨无法找到特定对象。

1) Suppose I open a fresh markdown document and save it. 1)假设我打开一个新的降价文档并保存。

2) write a chunk that refers to some lm object in my workspace. 2)写一个块,引用我工作区中的某个lm对象。 call summary(mylmobject) 呼叫summary(mylmobject)

3) knitr it. 3)编织它。

Unfortunately the report is generated but the regression output cannot be shown because the object could not be found. 遗憾的是,生成了报告,但无法显示回归输出,因为无法找到该对象。 Note, it works in general if i just save the object to .Rdata and then load it directly from the markdown file. 注意,如果我只是将对象保存到.Rdata然后直接从markdown文件加载它,它通常工作。

Is there a way to use objects in R markdown that are in the current workspace? 有没有办法在当前工作区中使用R markdown中的对象? This would be really nice to show non R people some output while still working. 这对于非R人在继续工作的同时显示一些输出会非常好。

RStudio opens a new R session to knit() your R Markdown file, so the objects in your current working space will not be available to that session (they are two separate sessions). RStudio打开一个新的 R会话来knit()你的R Markdown文件,因此你当前工作空间中的对象将无法用于该会话(它们是两个独立的会话)。 Two solutions: 两种解决方案

  1. file a feature request to RStudio, asking them to support knitting in the current R session instead of forcibly starting a new session; 向RStudio提交功能请求 ,要求他们支持在当前R会话中编织,而不是强行启动新会话;
  2. knit manually by yourself: library(knitr); knit('your_file.Rmd') 自己手工编织: library(knitr); knit('your_file.Rmd') library(knitr); knit('your_file.Rmd') (or knit2html() if you want HTML output in one step, or rmarkdown::render() if you are using R Markdown v2 ) library(knitr); knit('your_file.Rmd') knit2html() library(knitr); knit('your_file.Rmd') (或knit2html()如果你想在一步中输出HTML,或者rmarkdown::render()如果你使用R Markdown v2

Might be easier to save you data from your other session using: 使用以下方法可能更容易从其他会话中保存数据:

save.image("C:/Users/Desktop/example_candelete.RData")

and then load it into your MD file: 然后将其加载到您的MD文件中:

load("C:/Users/Desktop/example_candelete.RData")

Markdownreports软件包专为在运行中解析降价文档而设计。

As Julien Colomb commented, I've found the best thing to do in this situation is to save the large objects and then load them explicitly while I'm tailoring the markdown. 正如Julien Colomb评论的那样,我发现在这种情况下最好的办法是保存大型对象,然后在我定制降价时明确加载它们。 This is a must if your data is coming through an ODBC and you don't want to run the entire queries repeatedly as you tinker with fonts and themes. 如果您的数据是通过ODBC发送的,并且您不希望在修改字体和主题时重复运行整个查询,则必须这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM