-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject_report_send.R
207 lines (154 loc) · 7.65 KB
/
project_report_send.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#' Make plot of network within html documents.
#' Summarize all programs.
#' Make a readme file at top project directory
#' copy to target.directory
#' Uses pander and pandoc unlike project_report
#' @param target.directory Location to send project report
#' @param source_info Source information list
#' @param send.data Logical to send data directory or not
#' @param graph.width Sankey Plot dimensions
#' @param graph.height Sankey Plot dimensions
#' @details Dose not assume source_info in workspace
#' @export
#'
project_report_send <- function (target.directory=source_info$project.path,source_info,send.data=FALSE, graph.width = 960, graph.height = 500)
{
library(pander)
library(devtools)
if(!require("rCharts")){install_github('rCharts','ramnathv')}
library(rCharts)
library(plyr)
make.relative.hyperlink <- function(files,links){
files <- gsub("^/","",gsub(source_info$project.path,"",files,fixed=TRUE))
link.command <- rep("", length(files))
for (file.iter in 1:length(files)) {
link.command[file.iter] <- paste0("<a href=\"file:",
files[file.iter], "\">", links[file.iter], "</a>")
}
return(link.command)
}
#See if Pander is installed
setwd(source_info$results.dir)
panderOptions("table.split.table",Inf)
evalsOptions("cache.dir",source_info$results.dir)
try({rm(myReport)})
myReport <<- Pandoc$new()
author <- ""
try({
git_binary_path <- git_path(NULL)
author <- system2(git_binary_path, paste("config --global user.name"),stdout=TRUE)
})
try(pandocinstalled<-myReport$export("test",open=FALSE))
if(!exists("pandocinstalled")){
# if(FALSE){
project_reporter(source_info, graph.width , graph.height )
return("Error: Pandoc is not installed on this computer")}else {
#require(R2HTML)
project.info <- get.project.info.si(source_info)
project.graph <- project.info$graph
E(project.graph)$weight = 0.1
edgelist <- get.data.frame(project.graph)
colnames(edgelist) <- c("source", "target", "value")
edgelist$source <- as.character(edgelist$source)
edgelist$target <- as.character(edgelist$target)
sankeyPlot <- rCharts$new()
sankeyPlot$setLib("http://timelyportfolio.github.io/rCharts_d3_sankey/libraries/widgets/d3_sankey")
sankeyPlot$set(data = edgelist, nodeWidth = 15, nodePadding = 10,
layout = 32, width = graph.width, height = graph.height)
project.graph.file <- file.path(source_info$results.dir,
"full_networks.html")
sankeyPlot$save(project.graph.file, cdn = TRUE)
support.names <- subset(project.info$all.files, description ==
"Support file")$fullname.abbr
edgelist <- subset(edgelist, !(source %in% support.names) &
!grepl("Session_info", edgelist$source, fixed = TRUE) &
!grepl("Session_info", edgelist$target, fixed = TRUE))
sankeyPlot <- rCharts$new()
sankeyPlot$setLib("http://timelyportfolio.github.io/rCharts_d3_sankey/libraries/widgets/d3_sankey")
sankeyPlot$set(data = edgelist, nodeWidth = 15, nodePadding = 10,
layout = 32, width = graph.width, height = graph.height)
reduced.project.graph.file <- file.path(source_info$results.dir,
"reduced_networks.html")
sankeyPlot$save(reduced.project.graph.file, cdn = TRUE)
programs <- subset(project.info$tree, !duplicated(source.file),
select = c("source.file", "source.file.path", "source.file.description"))
programs$source.file.fullname <- file.path(programs$source.file.path,
programs$source.file)
run.times <- ddply(project.info$tree, "source.file", function(x) {
last.run.time <- max(as.POSIXct(x$target.mod.time) -
as.POSIXct(x$source.run.time), na.rm = TRUE)
return(data.frame(last.run.time.sec = last.run.time))
})
tab.out <- merge(programs, run.times, by = "source.file")
tab.out$source.link <- make.relative.hyperlink(tab.out$source.file.fullname,
tab.out$source.file)
sorted.names <- V(project.info$graph)$file[topological.sort(project.info$graph)]
sorted.names <- sorted.names[sorted.names %in% tab.out$source.file]
tab.out <- tab.out[match(sorted.names, tab.out$source.file),
]
program.split <- split(project.info$tree, project.info$tree$source.file)
summaries.out <- lapply(program.split, program.io.table)
outputs <- list()
for (source.iter in names(summaries.out)) {
temp <- summaries.out[[source.iter]]
temp$File <- make.relative.hyperlink(temp$Fullname, temp$File)
outputs[[source.iter]] <- subset(temp, select = c("IO",
"File", "Description"))
}
myReport$title<-paste(source_info$project.id,'Project Summary')
myReport$author<-paste("IT2",author)
# R2HTML::HTML(subset(tab.out, select = c("source.link", "source.file.description",
# "last.run.time.sec")), caption = paste(source_info$project.id,
# "Project Summary"), captionalign = "top")
tab.out0 <- subset(tab.out,select=c("source.link","source.file.description","last.run.time.sec"))
#rownames(tab.out0) <- 1:nrow(tab.out0)
tabtopander <<- tab.out0
rownames(tabtopander) <<- 1:nrow(tabtopander)
myReport$add(tabtopander)
#print(subset(tab.out,select=c("source.link","source.file.description","last.run.time.sec")))
# R2HTML::HTML(data.frame(Big_Graph = make.hyperlink(project.graph.file,
# "Project Graph")), align = "center")
tabtopander <<- data.frame(Big_Graph = make.relative.hyperlink(project.graph.file, "Project Graph"))
rownames(tabtopander) <<- 1:nrow(tabtopander)
myReport$add(tabtopander)
# R2HTML::HTML(data.frame(No_support_file_graph = make.hyperlink(reduced.project.graph.file,
# "Project Graph")), align = "center")
tabtopander <<- data.frame(No_support_file_graph = make.relative.hyperlink(reduced.project.graph.file,"Project Graph"))
rownames(tabtopander) <<- 1:nrow(tabtopander)
myReport$add(tabtopander)
for (namer in names(outputs)){
myReport$add.paragraph(namer)
tabtopander <<- subset(outputs[[namer]], Description !="Support file")
rownames(tabtopander) <<- 1:nrow(tabtopander)
myReport$add( tabtopander)
}
myReport$add.paragraph("Support files")
rownames(tabtopander) <<- 1:nrow(tabtopander)
tabtopander <<-subset(rbind.fill(outputs), (!duplicated(File)) &(Description == "Support file"))
myReport$add( tabtopander)
myReport$format<-'html'
myReport$export("project_summary",open=FALSE)
file.copy(file.path(source_info$results.dir,"project_summary.html"),file.path(source_info$project.path,"project_summary.html"))
all.files <- list.files(source_info$project.path,recursive=TRUE)
if(!send.data){
all.files <- all.files[!grepl("^Data",all.files)]
}
tempwd <- getwd()
setwd(source_info$project.path)
#target.directory <- "/Volumes/WORKING/Gelfond_Swap"
if(target.directory!=source_info$project.path){
targetdir <- file.path(target.directory,paste0("Results_",source_info$project.id))
dir.create(targetdir)
udirs <- setdiff(unique(dirname(all.files)),".")
sapply(file.path(targetdir,udirs ),function(x){dir.create(x,recursive=TRUE,showWarnings=FALSE)})
nfiles <- length(all.files)
for(file.iter in 1:nfiles){
fn <- all.files[file.iter]
dir <- dirname(all.files[file.iter])
file.copy(fn,file.path(targetdir,dir))
}
}
setwd(tempwd)
# R2HTML::HTMLStop()
}
}