R语言观察日志(part6)--初识rMarkdown
生活随笔
收集整理的這篇文章主要介紹了
R语言观察日志(part6)--初识rMarkdown
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
學習筆記,僅供參考,有錯必糾
官方文檔:rmarkdown
R Markdwon
初識R Markdown
創建一個R Markdwon:
選擇html為輸出格式,并給自己的文檔起一個名字:
點擊OK,系統自動生成一個示例Rmarkdown:
--- title: "myRmarkdwon" author: "goatbishop" date: "2020年7月9日" output: html_document ---```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ```## R MarkdownThis is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.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. You can embed an R code chunk like this:```{r cars} summary(cars) ```## Including PlotsYou can also embed plots, for example:```{r pressure, echo=FALSE} plot(pressure) ```Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.我們對R Markdown 里的內容進行修改:
--- title: "myRmarkdwon" author: "goatbishop" date: "2020年7月9日" output: html_document ---```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ```設置include參數為False,可以使代碼及結果都不顯示在報告中### 我的第一個R Markdown```{r cars} summary(cars) print("Hello Goatbishop, Welcome to R Markdown") ```### 繪圖```{r pressure, echo=FALSE} plot(pressure) ```我們設置echo參數為False,可以使代碼不顯示在報告中。點擊保存生成Rmd文件:
再新建一個R腳本,敲入如下代碼,就可以生成HTML報告文件:
library(rmarkdown) render("test2.Rmd")我們看一下Rstudio中的輸出結果:
> render("test2.Rmd")processing file: test2.Rmd|................ | 14%ordinary text without R code|................................ | 29% label: setup (with options) List of 1$ include: logi FALSE|................................................ | 43%ordinary text without R code|............................................................... | 57% label: cars|............................................................................... | 71%ordinary text without R code|............................................................................................... | 86% label: pressure (with options) List of 1$ echo: logi FALSE|...............................................................................................................| 100%ordinary text without R codeoutput file: test2.knit.md"F:/software/Rstudio/bin/pandoc/pandoc" +RTS -K512m -RTS test2.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output test2.html --email-obfuscation none --self-contained --standalone --section-divs --template "F:\software\R-3.6.2\library\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\GOATBI~1\AppData\Local\Temp\RtmpKMmluQ\rmarkdown-str4f025ca3a60.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"再看看新生成的test2.html文件:
打開它:
額,感覺我設計的有點問題,頁面很不美觀啊!沒關系,之后我們會繼續學習相關知識點的!
總結
以上是生活随笔為你收集整理的R语言观察日志(part6)--初识rMarkdown的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iPhone手机屏幕分辨率(苹果手机最大
- 下一篇: 腾讯视频 / 爱奇艺 / QQ 音乐每月