def _writeChunk(chunk, i, outfile, sep, missingValues, colnames, idcol):
    """Write a chunk of data to a file.

    :arg chunk:         ``pandas.DataFrame`` containing the data to write
    :arg i:             Chunk index - if ``0``, column headers are written
    :arg outfile:       File to write to
    :arg sep:           Separater character
    :arg missingValues: String to use for missing values
    :arg colnames:      Names for all columns
    :arg idcol:         Name for the index column
    """
    if i > 0:
        mode = 'a'
        colnames = False
        idcol = None
    else:
        mode = 'w'
    chunk.to_csv(outfile, sep=sep, na_rep=missingValues, header=colnames,
        index_label=idcol, mode=mode)
