20
20
# ' @param add_tbl_name_split (`flag`)\cr when `TRUE` and when the table has more than one
21
21
# ' `analyze(table_names = "<diff_names>")`, the table names will be present as a group split named
22
22
# ' `"<analysis_spl_tbl_name>"`.
23
+ # ' @param verbose (`flag`)\cr when `TRUE`, the function will print additional information for
24
+ # ' `data_format != "full_precision"`.
23
25
# ' @param ... additional arguments passed to spec-specific result data frame function (`spec`).
24
26
# '
25
27
# ' @return
@@ -46,6 +48,7 @@ as_result_df <- function(tt, spec = NULL,
46
48
keep_label_rows = FALSE ,
47
49
add_tbl_name_split = FALSE ,
48
50
simplify = FALSE ,
51
+ verbose = FALSE ,
49
52
... ) {
50
53
data_format <- data_format [[1 ]]
51
54
checkmate :: assert_class(tt , " VTableTree" )
@@ -56,6 +59,7 @@ as_result_df <- function(tt, spec = NULL,
56
59
checkmate :: assert_flag(keep_label_rows )
57
60
checkmate :: assert_flag(simplify )
58
61
checkmate :: assert_flag(add_tbl_name_split )
62
+ checkmate :: assert_flag(verbose )
59
63
60
64
if (nrow(tt ) == 0 ) {
61
65
return (sanitize_table_struct(tt ))
@@ -70,7 +74,7 @@ as_result_df <- function(tt, spec = NULL,
70
74
if (is.null(spec )) {
71
75
# raw values
72
76
rawvals <- cell_values(tt )
73
- cellvals <- .make_df_from_raw_data(rawvals , nr = nrow(tt ), nc = ncol(tt ))
77
+ cellvals_init <- .make_df_from_raw_data(rawvals , nr = nrow(tt ), nc = ncol(tt ))
74
78
75
79
if (data_format %in% c(" strings" , " numeric" )) {
76
80
# we keep previous calculations to check the format of the data
@@ -80,15 +84,17 @@ as_result_df <- function(tt, spec = NULL,
80
84
mf_result_numeric <- .make_numeric_char_mf(mf_result_chars )
81
85
mf_result_chars <- as.data.frame(mf_result_chars )
82
86
mf_result_numeric <- as.data.frame(mf_result_numeric )
83
- if (! setequal(dim(mf_result_numeric ), dim(cellvals )) || ! setequal(dim(mf_result_chars ), dim(cellvals ))) {
87
+ cond1 <- ! setequal(dim(mf_result_chars ), dim(cellvals_init ))
88
+ cond2 <- ! setequal(dim(mf_result_numeric ), dim(cellvals_init ))
89
+ if (cond1 || cond2 ) {
84
90
stop(
85
91
" The extracted numeric data.frame does not have the same dimension of the" ,
86
92
" cell values extracted with cell_values(). This is a bug. Please report it."
87
93
) # nocov
88
94
}
89
95
90
- colnames(mf_result_chars ) <- colnames(cellvals )
91
- colnames(mf_result_numeric ) <- colnames(cellvals )
96
+ colnames(mf_result_chars ) <- colnames(cellvals_init )
97
+ colnames(mf_result_numeric ) <- colnames(cellvals_init )
92
98
if (data_format == " strings" ) {
93
99
cellvals <- mf_result_chars
94
100
if (isTRUE(make_ard )) {
@@ -101,6 +107,41 @@ as_result_df <- function(tt, spec = NULL,
101
107
cellvals <- mf_result_numeric
102
108
}
103
109
}
110
+
111
+ diff_in_cellvals <- length(unlist(cellvals_init )) - length(unlist(cellvals ))
112
+ if (make_ard && abs(diff_in_cellvals ) > 0 ) {
113
+ warning_msg <- paste0(
114
+ " Found " , abs(diff_in_cellvals ), " cell values that differ from " ,
115
+ " printed values. This is possibly related to conditional formatting. "
116
+ )
117
+
118
+ # number of values difference mask between cellvals and cellvals_init (TRUE if different)
119
+ dmc <- lengths(unlist(cellvals , recursive = FALSE )) != lengths(unlist(cellvals_init , recursive = FALSE ))
120
+ dmc <- matrix (dmc , nrow = nrow(cellvals ), ncol = ncol(cellvals ))
121
+
122
+ # Mainly used for debugging
123
+ selected_rows_to_print <- mf_strings(mf_tt )[- seq_len(mf_nlheader(mf_tt )), , drop = FALSE ]
124
+ selected_rows_to_print <- cbind(
125
+ which(apply(dmc , 1 , any , simplify = TRUE )),
126
+ as.data.frame(selected_rows_to_print [apply(dmc , 1 , any ), , drop = FALSE ])
127
+ )
128
+ colnames(selected_rows_to_print ) <- c(" row_number" , " row_name" , colnames(cellvals_init ))
129
+ warning_msg <- if (verbose ) {
130
+ paste0(
131
+ warning_msg ,
132
+ " \n " ,
133
+ " The following row names were modified: " ,
134
+ paste(selected_rows_to_print $ row_name , sep = " , " , collapse = " , " ),
135
+ " \n "
136
+ )
137
+ } else {
138
+ paste0(warning_msg , " To see the affected row names use `verbose = TRUE`." )
139
+ }
140
+ warning(warning_msg )
141
+ cellvals [dmc ] <- cellvals_init [dmc ]
142
+ }
143
+ } else {
144
+ cellvals <- cellvals_init
104
145
}
105
146
106
147
rdf <- make_row_df(tt )
@@ -115,7 +156,11 @@ as_result_df <- function(tt, spec = NULL,
115
156
# Correcting maxlen for even number of paths (only multianalysis diff table names)
116
157
maxlen <- max(lengths(df $ path ))
117
158
if (maxlen %% 2 != 0 ) {
118
- maxlen <- maxlen + 1
159
+ maxlen <- if (add_tbl_name_split ) {
160
+ maxlen + 1
161
+ } else {
162
+ maxlen - 1
163
+ }
119
164
}
120
165
121
166
# Loop for metadata (path and details from make_row_df)
@@ -299,7 +344,7 @@ as_result_df <- function(tt, spec = NULL,
299
344
if (! " already_done" %in% names(list (... ))) {
300
345
stat_string_ret <- as_result_df(
301
346
tt = tt , spec = spec , data_format = " numeric" ,
302
- make_ard = TRUE , already_done = TRUE , ...
347
+ make_ard = TRUE , already_done = TRUE , verbose = verbose , ...
303
348
)
304
349
ret_w_cols <- cbind(ret_w_cols , " stat_string" = stat_string_ret $ stat )
305
350
}
0 commit comments