@@ -52,7 +52,8 @@ generate_hw_pkg = function(x,
5252 output_dir = paste0(name , " -" , type ),
5353 render_files = TRUE ,
5454 zip_files = TRUE ,
55- file_dependencies = NULL ) {
55+ hw_directory = ' ' ,
56+ file_dependencies = character (0 )) {
5657
5758 if (length(remove_indexes ) > 0 ) {
5859 # create assignment output lines
@@ -72,8 +73,16 @@ generate_hw_pkg = function(x,
7273
7374 # Fill directory
7475 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 ))
7786 }
7887
7988 # Name of Rmd file to build
@@ -112,9 +121,22 @@ extract_hw_name = function(x) {
112121
113122}
114123
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
118140}
119141
120142# ' Retrieve example file path
@@ -185,16 +207,23 @@ assignr = function(file,
185207 zip_files = TRUE ,
186208 render_files = TRUE ) {
187209
210+ # Minimal conditions for processing.
188211 if (length(file ) != 1 ) {
189212 stop(" Only one file may be processed at time." )
190213 } else if (! grep( " -main.Rmd$" , file )) {
191214 stop(" Supplied file must have -main.Rmd" )
192215 }
193216
217+ # Retrieve value before -main.Rmd
194218 hw_name = extract_hw_name(file )
195219
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 )
197225
226+ # Begin processing chunks
198227 input_lines = readLines(file )
199228
200229 chunk_tick_lines = detect_positions(input_lines , " ```" )
@@ -235,6 +264,7 @@ assignr = function(file,
235264 output_dir = output_dir ,
236265 render_files = render_files ,
237266 zip_files = zip_files ,
267+ hw_directory = hw_directory ,
238268 file_dependencies = hw_dependency_files
239269 )
240270 }
@@ -248,6 +278,7 @@ assignr = function(file,
248278 output_dir = output_dir ,
249279 render_files = render_files ,
250280 zip_files = zip_files ,
281+ hw_directory = hw_directory ,
251282 file_dependencies = hw_dependency_files
252283 )
253284 }
0 commit comments