楼主: oliyiyi
1119 1

Minimal examples Examples for Rnw, Markdown, HTML and LaTeX [推广有奖]

版主

泰斗

0%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
271951 个
通用积分
31269.3519
学术水平
1435 点
热心指数
1554 点
信用等级
1345 点
经验
383775 点
帖子
9598
精华
66
在线时间
5468 小时
注册时间
2007-5-21
最后登录
2024-4-18

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

[size=1.2em]For beginners, it is probably a good idea to start with some minimal examples; here I provide a few examples for Rnw, LaTeX, Markdown and HTML, respectively.

How is a report generated from R code

[size=1.2em]Regardless of which format you use, the basic idea is the same: knitr extracts R code in the input document, evaluates it and writes the results to the output document. There are two types of R code: chunks (code as separate paragraphs) and inline R code. For example, here we show a code chunk (using traditional Sweave syntax):

Example text outside R code here; we know the value of pi is \Sexpr{pi}.<<my-label, eval=TRUE, dev='png'>>=set.seed(1213)  # for reproducibilityx = cumsum(rnorm(100))mean(x)  # mean of xplot(x, type = 'l')  # Brownian motion@Other text outside R code here.

[size=1.2em]After weaving this chunk, we get the output as below. Compare them and you will realize the inline code \Sexpr{pi} is replaced by the value of pi, and the code chunk is also evaluated – numerical results are printed and plots are inserted in the output as well.

Example text outside R code here; we know the value of pi is 3.1415926.set.seed(1213)  # for reproducibilityx = cumsum(rnorm(100))mean(x)  # mean of x## [1] -1.939758plot(x, type = 'l')  # Brownian motion

[size=1.2em]

Other text outside R code here.

[size=1.2em]Now hopefully you have got an idea of how automatic report generation works. There are many options of which we can make use to tune the results, for example, we can use echo=FALSEto hide the R souce code (usually you do not want R code to appear in a final report, unless you are writing a tutorial on R), or results='hide' to hide the printed results (e.g. you will not see ## [1] -1.939758 above if you use this option), or control the format, size and alignment of plots. Beside local chunk options which you write between << and >>=, you can also set options globally like:

knitr::opts_chunk$set(echo=FALSE, fig.path='myproject/plot-', cache=TRUE)

[size=1.2em]Once options are set globally, all the following chunks will be affected by these options, so if you use an option frequently in many chunks, you may want to set it globally.

[size=1.2em]The advantage of using knitr is obvious: you only maintain the source code, and whenever you want a report, you just knit the source code, and everything will be generated automatically (tables, plots and numbers in lines). There is no need to manually copy and paste anything. Next time if you data source is changed, you simply run the process again, and all results can be updated. Let computers do the tedious job, because this is what they are good at. Humans should focus on other jobs like the statistical analysis and organization of the report.


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Examples example minimal ExamP LaTeX examples

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html
沙发
hyq2003 发表于 2016-6-18 19:38:20 |只看作者 |坛友微信交流群
good job
已有 1 人评分论坛币 收起 理由
oliyiyi + 20 精彩帖子

总评分: 论坛币 + 20   查看全部评分

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 01:37