Skip to content

Commit

Permalink
got the column id right
Browse files Browse the repository at this point in the history
I had the "long_table" variable in the code that was from the code I copied this from. I changed it to "mapi", and now gets the column name correctly.
  • Loading branch information
lgperez committed Jul 17, 2018
1 parent 1e59288 commit e5ced23
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions r/io_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ readExcel <- function(xlsxFile){
readFieldMapsExcel <- function(xlsx_list, endCol = 19, endRow=46,startRow = 2,startCol=3){
xlsxs <- list(0)
for (i in seq_along(xlsx_list)) {
mapi <- readWorksheetFromFile(xlsx_list[1], sheet = 1,header=TRUE, #we assume all have the same fixed size
mapi <- readWorksheetFromFile(xlsx_list[i], sheet = 1,header=TRUE, #we assume all have the same fixed size
endCol = endCol, endRow=endRow,startRow = startRow,startCol=startCol)
mapi$row <- rownames(mapi) ## Add the row number to a column

#Get all values listed with the column and row corresponding
trial_column <- paste0("Col",endCol-startCol+1) #number of the last column corresponding to the trial
#TODO: fix the row |col|plot order from here
mapi <- melt(mapi, id.vars =c("row",trial_column))
mapi <- melt(mapi, id.vars =c("row","X."))
#rename the columnName column and keep just the number in the values
colnames(mapi)[2:4] <- c("trial","col","plot")
mapi$col <- gsub('Col', '', long_table$col)
mapi$col <- gsub('X', '', mapi$col)
#check for NA's in rows and remove those rows (they belong to an empty column in the field map)
na_inrow <- apply(mapi, 1, function(x){any(is.na(x))})
#Save the formated fieldmap in the list
Expand All @@ -47,7 +46,7 @@ readFieldMapsExcel <- function(xlsx_list, endCol = 19, endRow=46,startRow = 2,st

#Now put all the different fieldmaps in one table
rowcol_xlsxs <- do.call("rbind", xlsxs)
#Merge the plot and trial name
#Merge the plot and trial name, separate by underscore
rowcol_xlsxs$plot <- paste(rowcol_xlsxs$plot,rowcol_xlsxs$trial, sep="_")
#just order the columns as row |col| plot
rowcol_xlsxs <- rowcol_xlsxs[,c(1,3,4)]
Expand Down

0 comments on commit e5ced23

Please sign in to comment.