使用knitr从R中编写html
发布时间:2020-12-14 18:27:10 所属栏目:资源 来源:网络整理
导读:也许我错过了显而易见的事情,但我一直在努力寻找以下示例:我想使用knitr包将我在R中的分析报告写入html文件.我已经找到了stitch()函数,但是更好地控制哪些结果情节写入html,哪些不是.原则上我希望能够编写以下代码: # some dummy codelibrary(ggplot)data
也许我错过了显而易见的事情,但我一直在努力寻找以下示例:我想使用knitr包将我在R中的分析报告写入html文件.我已经找到了stitch()函数,但是更好地控制哪些结果&情节写入html,哪些不是.原则上我希望能够编写以下代码:
# some dummy code library(ggplot) data <- read.table('/Users/mydata',header=TRUE) model <- lm(Y~X*Y,data) # write this result to html: summary(model) 解决方法
我想我不明白你到底缺少什么,但这里有一个我做过的最小例子.要运行它
library(knitr) knit("r-report.html") 而这个例子. <HTML> <HEAD> <TITLE>Analyzing Diamonds!</TITLE> </HEAD> <BODY> <H1>Diamonds are everywhere!</H1> <!--begin.rcode echo=FALSE ## Load libraries,but do not show this library(ggplot2) library(plyr) testData <- rnorm(1) end.rcode--> This is an analysis of diamonds,load the data.<p> <!--begin.rcode echo=TRUE,fig.keep="all" # Load the data data(diamonds) # Preview head(diamonds) end.rcode--> Generate a figure,don't show code <p> <!--begin.rcode echo=FALSE,fig.align="center",dev="png" # This code is not shown,but figure will output qplot(diamonds$color,fill=diamonds$color) + opts(title="A plot title") end.rcode--> Show some code,don't output the figure<p> <!--begin.rcode echo=TRUE,fig.keep="none" # Show the code for this one,but don't write out the figure ggplot(diamonds,aes(carat,price,colour=cut)) + geom_point(aes(alpha=0.9)) end.rcode--> And the value testData: <!--rinline testData --> inside a text block. </BODY> </HTML> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- html – ngDialog – closeModal事件 – angularjs
- html – 在flexbox中使用’height:100%’和’align-items
- 表单 – 使用yesod-form进行POST / Redirect / GET后保持不
- tsql – 使用多个列的CONTAINS进行FullText搜索,并使用谓词
- html – 如何在母版页菜单中突出显示活动页面?
- html – 一行中的CSS块元素
- html – 使用标记进行图像预取
- HTML – 如何将我的侧边栏扩展到页面的整个高度?
- JQuery中判断一个元素下面是否有内容或者有某个标签的判断代
- 表单 – 在Spring中提交重复表单[已关闭]