### fn.column.class.R
###------------------------------------------------------------------------------------------
### What: function to match csv column header with variable name and get column data type
###     : Column classes will be useful when reading CSV file. If column class is not provided 
###     : then R guess the type of column and lead to issues like leading zero missing
### Time-stamp: <2017-11-24 11:21:27 assyst>
###-------------------------------------------------------------------------------------------

column.class.csv <- function(variable,
                      file="",
                      ...)
{
    ## --- Setup ---
    # Read csv header to pick the column names
    csvHeader <- as.character(read.csv(file=file, nrows = 1, header = FALSE, sep =',', stringsAsFactors = FALSE))

    # Get column class by matching the type
    columnClasses <-lapply(csvHeader, function(x) {
        ifelse(x %in% variable$internalName,  as.character(variable[variable$internalName == x,]$type), "character")
    }) 

    return(columnClasses)
    
}

