@@ -406,7 +406,7 @@ pdf_preprocessing <- function(df, ref) {
406406# ' @return Named list containing the data frames which are now ready for download.
407407# '
408408# ' @keywords internal
409- prep_export_data <- function (data_selection , current_data , data_selection_name , dataset_list ) {
409+ prep_export_data <- function (data_selection , current_data , data_selection_name , dataset_list , footers ) {
410410 # check validity of parameters
411411 checkmate :: assert(
412412 checkmate :: check_string(data_selection ),
@@ -424,17 +424,31 @@ prep_export_data <- function(data_selection, current_data, data_selection_name,
424424 data_to_download <- dataset_list
425425 }
426426
427- names( data_to_download ) <- shorten_entries(
427+ shortened_names <- shorten_entries(
428428 paste0(names(data_to_download ), " (" , get_labels(data_to_download ), " )" ),
429429 as.integer(31 ) # name has to be shortened to 31 characters due to Excel's sheet name limit
430430 )
431431
432- # convert types to character to avoid representation issues in Excel
433- data_to_download <- lapply(data_to_download , function (df ) {
434- labels <- get_labels(df )
435- data <- data.frame (sapply(df , as.character ))
436- data <- set_labels(data , labels )
432+ data_to_download <- local({
433+ res <- list ()
434+ for (i_dataset in seq_along(data_to_download )){
435+ df <- data_to_download [[i_dataset ]]
436+
437+ # convert types to character to avoid representation issues in Excel
438+ labels <- get_labels(df )
439+ data <- data.frame (sapply(df , as.character ))
440+ data <- set_labels(data , labels )
441+
442+ # attach footer, if available
443+ dataset_name <- names(data_to_download )[[i_dataset ]]
444+ attr(data , " footer" ) <- footers [[dataset_name ]]
445+
446+ res [[length(res ) + 1 ]] <- data
447+ }
448+ return (res )
437449 })
450+
451+ names(data_to_download ) <- shortened_names
438452
439453 return (data_to_download )
440454}
@@ -458,9 +472,16 @@ excel_export <- function(data_to_download, file, intended_use_label) {
458472 combine = " and"
459473 )
460474
461- # Add column labels
475+ # Add column labels and footers
462476 data_to_download <- lapply(data_to_download , function (x ) {
463477 names(x ) <- paste0(names(x ), " [" , get_labels(x ), " ]" )
478+ footer <- attr(x , " footer" )
479+ if (! is.null(footer )) {
480+ first_new_row <- nrow(x ) + 1
481+ last_new_row <- nrow(x ) + length(footer )
482+ x [first_new_row : last_new_row , ] <- NA
483+ x [first_new_row : last_new_row , 1 ] <- footer
484+ }
464485 return (x )
465486 })
466487
@@ -522,6 +543,7 @@ pdf_export <- function(data_to_download, ref_cols, file, metadata, active_sessio
522543 trial_name = gsub(" _" , " \\\\ _" , metadata [1 ]), # Rmd does not allow underscore
523544 time_stamp = gsub(" [^-/A-Za-z0-9!?.,:() ]" , " ?" , metadata [2 ]), # replace characters that could cause problems
524545 snap_shot_name = gsub(" [^-/A-Za-z0-9!?.,:() ]" , " ?" , metadata [3 ]), # same here
546+ footer = attr(data_to_download [[1 ]], " footer" ),
525547 df_list = res_preprocess ,
526548 active_session = active_session
527549 ),
0 commit comments