楼主: oliyiyi
1408 1

Create Multiple Reports with RMarkdown [推广有奖]

版主

已卖:2994份资源

泰斗

1%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
101105 个
通用积分
31671.0967
学术水平
1454 点
热心指数
1573 点
信用等级
1364 点
经验
384134 点
帖子
9629
精华
66
在线时间
5508 小时
注册时间
2007-5-21
最后登录
2025-7-8

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

楼主
oliyiyi 发表于 2016-6-18 20:15:44 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
Create Multiple Reports with RMarkdownRich Majerus

Introduction

Using two files (an r script and an rmarkdown script) we can create a series of reports. The following example creates five reports using the first five rows of the mtcars data. The rmarkdown file is called by the rscript one time for each unique car name in the subset of the mtcars data. An example of the reports produced by these files can be found here.

The rscript and rmarkdown script referenced in this tutorial can be found here along with the rmarkdown file that creates this tutorial.



File 1: R Script# References for automation # http://www.r-bloggers.com/how-to ... automator-and-ical/# http://www.engadget.com/2013/03/ ... s-in-mountain-lion/# File 1: Should be an R-Script     # contains a loop that iteratively calls an Rmarkdown file (i.e. File 2)# load packageslibrary(knitr)library(markdown)library(rmarkdown)# use first 5 rows of mtcars as example datamtcars <- mtcars[1:5,# create map to plot data on (this is outside the loop so it is only called once)map <-  get_map(location="United States",          source= 'google', maptype = 'terrain', color='bw', zoom=4) # for each type of car in the data create a report  # these reports are saved in output_dir with the name specified by output_filefor (car in unique(rownames(mtcars))){  rmarkdown::render('/Users/majerus/Desktop/R/auto_reporting/test/r_script.Rmd',  # file 2                   output_file =  paste("report_", car, '_', Sys.Date(), ".html", sep=''),                    output_dir = '/Users/majerus/Desktop/R/auto_reporting/test/reports')# for pdf reports  #   rmarkdown::render(input = "/Users/majerus/Desktop/R/auto_reporting/test/r_script_pdf.Rmd", #           output_format = "pdf_document",#           output_file = paste("test_report_", car, Sys.Date(), ".pdf", sep=''),#           output_dir = "/Users/majerus/Desktop/R/auto_reporting/test/reports")  }

File 2: RmarkdownsuppressWarnings(suppressPackageStartupMessages(library(ggplot2)))suppressWarnings(suppressPackageStartupMessages(library(dplyr)))suppressWarnings(suppressPackageStartupMessages(library(leaflet)))suppressWarnings(suppressPackageStartupMessages(library(DT)))suppressWarnings(suppressPackageStartupMessages(library(stringr)))library(knitr)library(markdown)library(rmarkdown)# run report for current car listed in loop in R filecars <- mtcars[rownames(mtcars)==car,# create example data x <- sample(1:10, 1)cars <- do.call("rbind", replicate(x, cars, simplify = FALSE))# create hypothetical lat and lon data cars$lat <- sapply(rownames(cars), function(x) round(runif(1, 30, 46), 3))cars$lon <- sapply(rownames(cars), function(x) round(runif(1, -115, -80),3))

Today is 2015-04-22.


Today we sold cars to people in the following locations:

# map of cars soldleaflet(cars) %>%  addTiles() %>%  setView(-93.65, 42.0285, zoom = 3) %>%  addCircles(cars$lon, cars$lat)

Here is a data table of the cars we sold.

# data table of cars sold datatable(cars[,c(1:2, 12:13))

Here is a plot of mpg vs. weight for the sold cars:

# plot ggplot(cars, aes(mpg, wt)) +   geom_point(position = position_jitter(w = 0.1, h = 0.1)) +   stat_smooth(method="lm", se=TRUE)


二维码

扫码加我 拉你入群

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

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

关键词:Multiple Reports Report Create multip Create

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

沙发
hyq2003 发表于 2016-6-18 20:35:42
发了不少 R markdown 的帖子,辛苦了。

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-21 22:53