全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 LATEX论坛
1515 4
2016-06-18
Tutorial R MarkdownJacolien van Rij


Table of contents



Using R Markdown as analysis script

This tutorial describes how to use R Markdown. R Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. Example: this tutorial itself is generated with R Markdown.

For more details on using R Markdown see http://rmarkdown.rstudio.com.

Some advantages of using R Markdown:

  • R code can be embedded in the report, so it is not necessary to keep the report and R script separately. Including the R code directly in a report provides structure to analyses.

  • The report text is written as normal text, so no knowledge of HTML coding is required.

  • The output is an HTML file that includes pictures, code blocks R output and text. No additional files are needed, everything is incorporated in the HTML file. So easy to send the report via mail, or place it as paper package on your website.

  • These HTML reports enhance collaboration: It is much more easy to comment on an analysis when the R code, the R output and the plots are available in the report.




二维码

扫码加我 拉你入群

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

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

全部回复
2016-6-18 18:32:15
How to generate an HTML reportMethod 1: Start a new R Markdown file in R Studio

Open R Studio, then go to File \(\rightarrow\) New file \(\rightarrow\) R Markdown.





二维码

扫码加我 拉你入群

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

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

2016-6-18 18:34:09
11111.png
二维码

扫码加我 拉你入群

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

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

2016-6-18 18:34:43

Choose a title and author, but leave the rest as it is, and press the OK button:


The R markdown file you opened, already contains example code.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document:

More info on how to format the HTML report in the section Formatting the report.


二维码

扫码加我 拉你入群

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

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

2016-6-18 18:35:10
Method 2: If you really don’t want to use R Studio…

This method requires that pandoc document converter software is installed (see instructions on the pandoc website).

After pandoc is installed, install the R package rmarkdown and it’s dependencies. Type the following command in the R console:

install.packages("rmarkdown", repos="http://cran.us.r-project.org")

Download here a template of a markdown file (from R Studio) and store it in your working directory: download template.

Open the file template.Rmd in a text editor, and add your R code in the code blocks, which start with ```{r}` and end with ```. Around the blocks you could type your report. Example code is provided in the file template.Rmd.

Run the following code in the R console to convert the .Rmd file to an HTML report (courtesy of Martijn Wieling):

# make sure to have the package rmarkdown updated and installed:library(rmarkdown)# generates html file with resultsrender('template.Rmd')

The render function will generate an HTML file in your working directory. You could view the HTML in your browser, or use the following code to view the result in R:

browseURL(sprintf('file://%s%s', 'template.html', file.path(getwd())))

More info on how to format the HTML report in the section Formatting the report.


二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群