@@ -52,7 +52,8 @@ generate_hw_pkg = function(x,
52
52
output_dir = paste0(name , " -" , type ),
53
53
render_files = TRUE ,
54
54
zip_files = TRUE ,
55
- file_dependencies = NULL ) {
55
+ hw_directory = ' ' ,
56
+ file_dependencies = character (0 )) {
56
57
57
58
if (length(remove_indexes ) > 0 ) {
58
59
# create assignment output lines
@@ -72,8 +73,16 @@ generate_hw_pkg = function(x,
72
73
73
74
# Fill directory
74
75
if (length(file_dependencies ) > = 1 ) {
75
- file.copy(file_dependencies ,
76
- file.path(output_path , basename(file_dependencies )))
76
+
77
+ # Create any required directories for the copy
78
+ for (dir_dependent in unique(dirname(file_dependencies ))) {
79
+ dir.create(file.path(output_path , dir_dependent ),
80
+ showWarnings = FALSE , recursive = TRUE )
81
+ }
82
+
83
+ # Perform a vectorized copy to the appropriate directory
84
+ file.copy(file.path(hw_directory , file_dependencies ),
85
+ file.path(output_path , file_dependencies ))
77
86
}
78
87
79
88
# Name of Rmd file to build
@@ -112,9 +121,22 @@ extract_hw_name = function(x) {
112
121
113
122
}
114
123
115
- hw_dir_dependencies = function (x ) {
116
- main_dir_files = list.files(dirname(x ), full.names = TRUE , recursive = TRUE )
117
- grep(main_dir_files , pattern = ' -(main|assign|sol)' , invert = TRUE , value = TRUE )
124
+ hw_dir_dependencies = function (hw_directory ) {
125
+ # Move to where the file might be found
126
+ old_wd = setwd(file.path(hw_directory ))
127
+
128
+ # Determine all files and directories within the homework directory
129
+ main_dir_files = list.files(path = " ." , full.names = TRUE , recursive = TRUE )
130
+
131
+ # Avoid retrieving any file matching our exclusion list
132
+ hw_dependencies = grep(main_dir_files , pattern = ' -(main|assign|sol)' ,
133
+ invert = TRUE , value = TRUE )
134
+
135
+ # Return to original working directory
136
+ setwd(old_wd )
137
+
138
+ # Release files
139
+ hw_dependencies
118
140
}
119
141
120
142
# ' Retrieve example file path
@@ -185,16 +207,23 @@ assignr = function(file,
185
207
zip_files = TRUE ,
186
208
render_files = TRUE ) {
187
209
210
+ # Minimal conditions for processing.
188
211
if (length(file ) != 1 ) {
189
212
stop(" Only one file may be processed at time." )
190
213
} else if (! grep( " -main.Rmd$" , file )) {
191
214
stop(" Supplied file must have -main.Rmd" )
192
215
}
193
216
217
+ # Retrieve value before -main.Rmd
194
218
hw_name = extract_hw_name(file )
195
219
196
- hw_dependency_files = hw_dir_dependencies(file )
220
+ # Obtain location of the homework directory
221
+ hw_directory = dirname(file )
222
+
223
+ # Extract a local file structure
224
+ hw_dependency_files = hw_dir_dependencies(hw_directory )
197
225
226
+ # Begin processing chunks
198
227
input_lines = readLines(file )
199
228
200
229
chunk_tick_lines = detect_positions(input_lines , " ```" )
@@ -235,6 +264,7 @@ assignr = function(file,
235
264
output_dir = output_dir ,
236
265
render_files = render_files ,
237
266
zip_files = zip_files ,
267
+ hw_directory = hw_directory ,
238
268
file_dependencies = hw_dependency_files
239
269
)
240
270
}
@@ -248,6 +278,7 @@ assignr = function(file,
248
278
output_dir = output_dir ,
249
279
render_files = render_files ,
250
280
zip_files = zip_files ,
281
+ hw_directory = hw_directory ,
251
282
file_dependencies = hw_dependency_files
252
283
)
253
284
}
0 commit comments