17
17
html_all_figs_tables <- function (rda_dir = getwd()) {
18
18
if (! dir.exists(fs :: path(rda_dir , " rda_files" ))) {
19
19
stop(" 'rda_files' folder not found. Did you enter the correct argument for rda_dir?" )
20
+ }
21
+ # check if dir exists and present warning message/option message
22
+ if (dir.exists(fs :: path(getwd(), " all_tables_figures" ))) {
23
+ question1 <- readline(
24
+ " The 'all_tables_figures' folder already exists within your working directory. Would you like to overwrite the files within this folder? (Y/N)"
25
+ )
20
26
} else {
21
- if (! dir.exists(fs :: path(getwd(), " all_tables_figures" ))) {
22
- asar :: create_tables_doc(subdir = tempdir() ,
23
- include_all = TRUE ,
24
- rda_dir = rda_dir )
27
+ # indicate to proceed with function
28
+ question1 <- " y"
29
+ # create new folder for the html and qmd files
30
+ dir.create(fs :: path(rda_dir , " all_tables_figures" ))
31
+ doc_path <- fs :: path(rda_dir , " all_tables_figures" )
32
+ }
25
33
26
- asar :: create_figures_doc(subdir = tempdir(),
27
- include_all = TRUE ,
28
- rda_dir = rda_dir )
34
+ if (regexpr(question1 , " y" , ignore.case = TRUE ) == 1 ) {
35
+ asar :: create_tables_doc(
36
+ subdir = tempdir() ,
37
+ include_all = TRUE ,
38
+ rda_dir = rda_dir
39
+ )
29
40
30
- tabs_figs_text <- c(readLines(fs :: path(tempdir(), " 08_tables.qmd" )), readLines(fs :: path(tempdir(), " 09_figures.qmd" )))
41
+ asar :: create_figures_doc(
42
+ subdir = tempdir(),
43
+ include_all = TRUE ,
44
+ rda_dir = rda_dir
45
+ )
31
46
32
- yaml_text <-
47
+ tabs_figs_text <- c(readLines(fs :: path(tempdir(), " 08_tables.qmd" )), readLines(fs :: path(tempdir(), " 09_figures.qmd" )))
48
+
49
+ yaml_text <-
33
50
" ---
34
51
title: 'All Tables & Figures'
35
52
format:
@@ -39,99 +56,36 @@ format:
39
56
---
40
57
"
41
58
42
- new_html_qmd <- c(yaml_text , tabs_figs_text )
59
+ new_html_qmd <- c(yaml_text , tabs_figs_text )
43
60
44
- writeLines(new_html_qmd ,
45
- fs :: path(getwd() , " all_tables_figures.qmd" ))
46
- quarto :: quarto_render(
47
- input = fs :: path(getwd() , " all_tables_figures.qmd" ),
48
- output_file = " all_tables_figures.html"
49
- )
61
+ writeLines(new_html_qmd ,
62
+ fs :: path(rda_dir , " all_tables_figures.qmd" ))
63
+ quarto :: quarto_render(
64
+ input = fs :: path(rda_dir , " all_tables_figures.qmd" ),
65
+ output_file = " all_tables_figures.html"
66
+ )
50
67
51
- # create new folder for the html and qmd files because these can't
52
- # be saved there before or while rendering
53
- dir.create(fs :: path(getwd(), " all_tables_figures" ))
54
-
55
- file.rename(
56
- from = fs :: path(" all_tables_figures.html" ),
57
- to = fs :: path(
58
- getwd(),
59
- " all_tables_figures" ,
60
- " all_tables_figures.html"
61
- )
68
+ file.rename(
69
+ from = fs :: path(" all_tables_figures.html" ),
70
+ to = fs :: path(
71
+ doc_path ,
72
+ " all_tables_figures.html"
62
73
)
74
+ )
63
75
64
- file.rename(
65
- from = fs :: path(" all_tables_figures.qmd" ),
66
- to = fs :: path(getwd(), " all_tables_figures" , " all_tables_figures.qmd" )
76
+ file.rename(
77
+ from = fs :: path(" all_tables_figures.qmd" ),
78
+ to = fs :: path(
79
+ doc_path ,
80
+ " all_tables_figures.qmd"
67
81
)
82
+ )
68
83
69
- message(" The html and qmd with all tables and figures were newly created." )
70
-
71
- } else {
72
- question1 <- readline(
73
- " The 'all_tables_figures' folder already exists within your working directory. Would you like to overwrite the files within this folder? (Y/N)"
74
- )
84
+ message(
85
+ " The html and qmd with all tables and figures were generated and overwrote the previous versions."
86
+ )
75
87
76
- if (regexpr(question1 , " y" , ignore.case = TRUE ) == 1 ) {
77
- asar :: create_tables_doc(
78
- subdir = tempdir() ,
79
- include_all = TRUE ,
80
- rda_dir = rda_dir
81
- )
82
-
83
- asar :: create_figures_doc(
84
- subdir = tempdir(),
85
- include_all = TRUE ,
86
- rda_dir = rda_dir
87
- )
88
-
89
- tabs_figs_text <- c(readLines(fs :: path(tempdir(), " 08_tables.qmd" )), readLines(fs :: path(tempdir(), " 09_figures.qmd" )))
90
-
91
- yaml_text <-
92
- " ---
93
- title: 'All Tables & Figures'
94
- format:
95
- html:
96
- toc: true
97
- embed-resources: true
98
- ---
99
- "
100
-
101
- new_html_qmd <- c(yaml_text , tabs_figs_text )
102
-
103
- writeLines(new_html_qmd ,
104
- fs :: path(getwd(), " all_tables_figures.qmd" ))
105
- quarto :: quarto_render(
106
- input = fs :: path(getwd(), " all_tables_figures.qmd" ),
107
- output_file = " all_tables_figures.html"
108
- )
109
-
110
- file.rename(
111
- from = fs :: path(" all_tables_figures.html" ),
112
- to = fs :: path(
113
- getwd(),
114
- " all_tables_figures" ,
115
- " all_tables_figures.html"
116
- )
117
- )
118
-
119
- file.rename(
120
- from = fs :: path(" all_tables_figures.qmd" ),
121
- to = fs :: path(
122
- getwd(),
123
- " all_tables_figures" ,
124
- " all_tables_figures.qmd"
125
- )
126
- )
127
-
128
- message(
129
- " The html and qmd with all tables and figures were regenerated and overwrote the previous versions."
130
- )
131
-
132
- } else {
133
- warning(" The html and qmd with all tables and figures were not regenerated." )
134
- }
135
- }
88
+ } else {
89
+ warning(" The html and qmd with all tables and figures were not generated." )
136
90
}
137
91
}
0 commit comments