-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicon_creation_workflow.R
112 lines (95 loc) · 3.22 KB
/
icon_creation_workflow.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
#
# create pair icons f
#
library(knitr)
library(magick)
library(pdftools)
library(brotli)
library(base64enc)
target<-"synthetic_data"
target_directory<-gsub("\\\\","/",normalizePath(paste0(target)))
temp_files<-list.files(
path=paste0(target_directory,"/","tikz-figures"),
pattern="(^[A-Za-z0-9]+\\.dpth$)|(^[A-Za-z0-9]+\\.log$)|(^[A-Za-z0-9]+\\.md5$)|(^[A-Za-z0-9]+\\.pdf$)",
recursive = FALSE,
full.names = TRUE
)
file.remove(temp_files)
plot_files<-list.files(
path="figure",
pattern="(^[A-Za-z0-9]+\\.dpth$)|(^[A-Za-z0-9]+\\.log$)|(^[A-Za-z0-9]+\\.md5$)|(^[A-Za-z0-9]+\\.pdf$)",
recursive = FALSE,
full.names = TRUE
)
file.remove(plot_files)
#
# write the icon-generation job spec
# to a file where "create_synthetic_pair_icons.Rnw"
# will read it and direct its output accordingly
#
fwrite(data.table(
externalization_flag="ENABLE", # enable externalization
externalization_command=paste0("\\tikzexternalize[prefix=",paste0(target,"/","tikz-figures"),"/]"),
target=target,
data_directory=target_directory,
icon_directory=paste0(target_directory,"/","tikz-figures"),
timestamp=as.character(Sys.time()),
md5=digest(file.info(list.files(target_directory,full.names = TRUE))),
items=paste(fread(paste0(target_directory,"/","pair_col.csv"))$item,collapse=",")
),"icon_creation_job.csv")
knit("create_synthetic_pair_icons.Rnw")
system("pdflatex -shell-escape create_synthetic_pair_icons.tex")
# now disable externalization, so it does not happen a second time
fwrite(data.table(
externalization_flag="DISABLE",
externalization_command="",
target=target,
data_directory=target_directory,
icon_directory=paste0(target_directory,"/","tikz-figures"),
timestamp=as.character(Sys.time()),
md5=digest(file.info(list.files(target_directory,full.names = TRUE))),
items=paste(fread(paste0(target_directory,"/","pair_col.csv"))$item,collapse=",")
),"icon_creation_job.csv")
temp_files<-list.files(
path=paste0(target_directory,"/","tikz-figures"),
pattern="(^[A-Za-z0-9]+\\.dpth$)|(^[A-Za-z0-9]+\\.log$)|(^[A-Za-z0-9]+\\.md5$)",
recursive = FALSE,
full.names = TRUE
)
file.remove(temp_files)
#
# create name-to-image-filename maps
# for pair icons and other assets
#
images<-data.table(
file=list.files(
path=paste0(target_directory,"/","tikz-figures"),
pattern="^[A-Za-z0-9]+\\.pdf$",
recursive = FALSE,
full.names = TRUE
),
name=gsub("\\.pdf$","",list.files(
path=paste0(target_directory,"/","tikz-figures"),
pattern="^[A-Za-z0-9]+\\.pdf$",
recursive = FALSE,
full.names = FALSE
))
)[!grepl("^ICON",name)]
keys<-data.table(
file=list.files(
path=paste0(target_directory,"/","tikz-figures"),
pattern="^[A-Za-z0-9]+\\.pdf$",
recursive = FALSE,
full.names = TRUE
),
name=gsub("\\.pdf$","",list.files(
path=paste0(target_directory,"/","tikz-figures"),
pattern="^[A-Za-z0-9]+\\.pdf$",
recursive = FALSE,
full.names = FALSE
))
)[grepl("^ICON",name)]
fwrite(images,paste0(target_directory,"/","images.csv"))
fwrite(keys,paste0(target_directory,"/","keys.csv"))
x<-mapply(function(f)image_read(pdf_render_page(f,page=1,dpi=300)),images$file,SIMPLIFY = FALSE)
y<-mapply(function(f)image_read(pdf_render_page(f,page=1,dpi=300)),keys$file,SIMPLIFY = FALSE)