Index: trunk/tools/wsor/message_templates/R/R_helper_functions.R |
— | — | @@ -158,7 +158,7 @@ |
159 | 159 | # Assumes: the two data frames have the same column names |
160 | 160 | # |
161 | 161 | |
162 | | -append.data.frames <- function(df_1, df_2) { |
| 162 | +append.data.frames <- function(df_1, df_2, string_frames=c(0)) { |
163 | 163 | |
164 | 164 | df_cols <- length(colnames(df_1)) |
165 | 165 | df_rows_1 <- length(df_1[[1]]) |
— | — | @@ -169,13 +169,22 @@ |
170 | 170 | |
171 | 171 | for (i in 1:df_cols) |
172 | 172 | for (j in 1:df_rows_1) |
173 | | - df_return[colnames(df_return)[i]][[1]][j] <- df_1[colnames(df_1)[i]][[1]][j] |
174 | | - |
| 173 | + { |
| 174 | + if (i %in% string_frames) |
| 175 | + df_return[colnames(df_return)[i]][[1]][j] <- toString(df_1[colnames(df_1)[i]][[1]][j]) |
| 176 | + else |
| 177 | + df_return[colnames(df_return)[i]][[1]][j] <- df_1[colnames(df_1)[i]][[1]][j] |
| 178 | + } |
| 179 | + |
175 | 180 | for (i in 1:df_cols) |
176 | 181 | for (j in 1:df_rows_2) |
177 | 182 | { |
178 | 183 | row_index <- j + df_rows_1 |
179 | | - df_return[colnames(df_return)[i]][[1]][row_index] <- df_2[colnames(df_1)[i]][[1]][j] |
| 184 | + |
| 185 | + if (i %in% string_frames) |
| 186 | + df_return[colnames(df_return)[i]][[1]][row_index] <- toString(df_2[colnames(df_1)[i]][[1]][j]) |
| 187 | + else |
| 188 | + df_return[colnames(df_return)[i]][[1]][row_index] <- df_2[colnames(df_1)[i]][[1]][j] |
180 | 189 | } |
181 | 190 | |
182 | 191 | # create the new data list |
— | — | @@ -194,13 +203,12 @@ |
195 | 204 | # Constructs a concatenated data.frame from files |
196 | 205 | # |
197 | 206 | |
198 | | -build.data.frames <- function(template_indices, fname_first_part, fname_last_part) { |
| 207 | +build.data.frames <- function(template_indices, fname_first_part, fname_last_part, string_frames=c(0)) { |
199 | 208 | |
200 | 209 | # Initialize the data frame |
201 | 210 | |
202 | 211 | filename <- paste(fname_first_part, template_indices[1], fname_last_part, sep="") |
203 | 212 | metrics = read.table(filename, na.strings="\\N", sep="\t", comment.char="", quote="", header=T) |
204 | | - |
205 | 213 | output <- paste("Processing data from",filename,"....") |
206 | 214 | print(output) |
207 | 215 | |
— | — | @@ -216,10 +224,10 @@ |
217 | 225 | output <- paste("Processing data from",filename,"....") |
218 | 226 | print(output) |
219 | 227 | |
220 | | - temp_frame = read.table(filename, na.strings="\\N", sep="\t", comment.char="", quote="", header=T) |
221 | | - metrics <- append.data.frames(metrics, temp_frame) |
| 228 | + temp_frame = read.table(filename, na.strings="\\N", sep="\t", comment.char="", quote="", header=T) |
| 229 | + metrics <- append.data.frames(metrics, temp_frame, string_frames=string_frames) |
222 | 230 | } |
223 | | - |
| 231 | + |
224 | 232 | metrics |
225 | 233 | } |
226 | 234 | |
— | — | @@ -275,3 +283,19 @@ |
276 | 284 | value_list |
277 | 285 | } |
278 | 286 | |
| 287 | + |
| 288 | +# FUNCTION :: filter.list.by.regex |
| 289 | +# |
| 290 | +# Take a list and filter out elements that don't match the pattern |
| 291 | +# |
| 292 | + |
| 293 | +filter.list.by.regex <- function(pattern, value_list) { |
| 294 | + new_list <- c() |
| 295 | + for (i in 1:length(value_list)) |
| 296 | + if (length(grep(pattern, value_list[i], perl = TRUE)) > 0) |
| 297 | + new_list <- c(new_list, TRUE) |
| 298 | + else |
| 299 | + new_list <- c(new_list, FALSE) |
| 300 | + new_list |
| 301 | +} |
| 302 | + |