## jesus_parse_old.r 
## These are the PRIOR versions of the parse files






#      parseBackUpFile <- function(fileString, MayContainPath=TRUE, sep=get_jesus_sep.major(), info.sep=get_jesus_sep.minor(), fsep=.Platform$file.sep, pat.time="^(\\d{8}_\\d{4,6})$") {
#      # sep:  what string pattern sepearates the object infos
#      
#        ## Pattern for the dim Info - it will either be 9999x99  or 999_len
#        pat.dim <- "\\d{1,}(x\\d{1,}|\\d{1,}_len)"
#        # update, why not:  "\\d{1,}(x\\d{1,}|_len)"
#      
#        ## ERROR CHECK
#        ## --------------------
#        # only one at a time
#        if (!length(fileString) == 1L)
#          stop ("Only one file at a time. (ie, fileString must have length 1)")
#        # only basename
#        if (fileString != basename(fileString))  ## this COULD be a warning, however, this error is probably indicative of a bug upstream.
#          stop ("fileString is not the basename of the file")
#        ## --------------------
#      
#        # take just the file name
#        if (MayContainPath) {
#          fileString <- sapply(strsplit(fileString, fsep), tail, 1L)  
#        }
#        
#        splat <- strsplit(fileString, sep)[[1]]
#        ln <- length(splat)
#      
#        if (!(ln>=1)) {
#          stop ("Something is not write. Executing\n   strsplit(\"", fileString, "\", \"", sep, "\")\nreturned no result.")
#        }
#      
#        # sep for file extension
#        sep.ext <- "\\."
#        # if sep.ext is not found, manually add a blank value
#        # Dont try to split and assign, becuase original value will be recycled
#        splat[ln + (0:1)] <- {
#          if (!grepl(sep.ext, splat[[ln]]))
#            c(splat[[ln]], "")
#          else
#            splitOnLast(string=splat[[ln]], splitOn=sep.ext) [[1L]]
#         }
#      
#         ## Split the object name based on info.sep
#           ## Splice out info
#           NameAndInfo <- strsplit(splat[[1]], escapeRegEx(info.sep))[[1L]]
#           
#           ## Check for too few or too many words resulting from the split on info.sep
#           L <- length(NameAndInfo)
#           if (L == 1L)
#              NameAndInfo <- c(NameAndInfo, "")
#           if (L > 2L) {
#              warning(sprintf("More than one '%s' sep in filename:  '%s'\n", info.sep, fileString))
#              NameAndInfo <- c(paste(NameAndInfo[1:(L-1)], collapse=info.sep), NameAndInfo[L])
#           }
#      
#           ## Put it back into splat
#      #    if (L == 2L) {
#      #      NameAndInfo[[2L]] <- cropStringTo(NameAndInfo[[2L]], info.maxchar)
#      #      splat[[1]] <- sprintf("%s  (%s)", NameAndInfo[[1L]], gsub("_", " ", NameAndInfo[[2L]]) )
#      #     }
#           splat <- c(NameAndInfo, splat[-1L])
#         ## End- Split the object name based on info.sep
#      
#      
#        # identify which column is which
#        nameCol <- 1L
#        infoCol <- 2L
#        timeCol <- which(grepl(pat.time, splat))
#        dimCol  <- which(grepl(pat.dim, splat))
#        extCol  <- length(splat)
#      
#        ## Debugging
#        browser(expr=inDebugMode("jesus", skip="parseBackUpFile"), text="In parseBackUpFile().\n\nCheck Forthcoming AllCols,\n\t and the different logical branches.")
#      
#        ## 'Allcols': is the collection of integers, representing all possible pieces of informaiton 
#        ##     that might be in the file name. 
#        ## 'nms': are the column names for the final output table. 
#        ##        Since some of the parts composing AllCols might be missing, we need
#        ##        to filter out 'AllCols' accordingly.
#        ##        eg: c("obj", "info", "time" , "dims", "ext")
#        ##
#        ## Note that if any of the 'which(grepl(..))' calls above did not find a match
#        ## then when c(..)'d  into AllCols, it simply will not be included
#        ## this leaving AllCols with a slightly shorter length than expected
#        AllCols <- c(nameCol, infoCol, timeCol, dimCol, extCol)
#        nms  <- c("obj", "info", if (length(timeCol)) "time" , if (length(dimCol)) "dims", "ext")
#      
#        ## if the lengths match, then all columns are present as expected, with no surprises
#        if (length(AllCols) == length(splat)) {
#          ret <- setNames(splat[AllCols], nms)
#        ## Otherwise...
#        } else  {
#          ## There are two non-exclusive possibilities to account for
#          ## (1) Some expected column not found
#          ## (2) Superfluous Column exist in splat
#      
#          ## Start with (1).  
#          ##   We check if there were no matches for 
#          ##       timeCol & dimCol, which were calculated above
#          ##   Add in blanks, then recalculate AllCols
#          if (!length(timeCol)) {
#            splat   <- c(splat, "")
#            timeCol <- length(splat)
#          }
#          if (!length(dimCol)) {
#            splat  <- c(splat, "")
#            dimCol <- length(splat)
#          }
#          
#          ### TODO:  ehhh... why am I using this line? 
#          # recalculate AllCols
#          ### SKIPPING THIS LINE
#          #### AllCols <- c(nameCol, infoCol, timeCol, dimCol, extCol)
#          # Add in any superfluous cols
#          cols.missing <- setdiff(seq_along(splat), AllCols)
#          AllCols      <- c(AllCols, cols.missing)
#      
#          ret <- setNames(splat[AllCols], nms)
#          NA.nms <- is.na(names(ret))
#          if (any(NA.nms))
#            names(ret)[NA.nms] <- paste0("Addl", seq(sum(NA.nms)))
#        }
#      
#        ## older files may not 
#        if (!"dims" %in% names(ret))
#          ret[["dims"]] <- " x "
#      
#        ret[["dims"]] <- gsub("\\!", "", ret[["dims"]])
#        ret[c("rows", "cols")] <- strsplit(ret[["dims"]], "x|_") [[1]]
#      
#        # ret[["dims"]] <- 
#        #   gsub("x", " x ",
#        #     gsub("_len", " (len)", 
#        #        gsub("\\!", "", 
#        #         ret[["dims"]]
#        #         )))
#      
#        return(ret[names(ret)!= "dims"])
#      }
