Delimited Files

    Read a matrix from the source where each line (separated by ) gives one row, with elements separated by the given delimiter. The source can be a text file, stream or byte array. Memory mapped files can be used by passing the byte array representation of the mapped segment as source.

    If T is a numeric type, the result is an array of that type, with any non-numeric elements as NaN for floating-point types, or zero. Other useful values of T include String, AbstractString, and Any.

    If header is true, the first row of data will be read as header and the tuple (data_cells, header_cells) is returned instead of only data_cells.

    Specifying skipstart will ignore the corresponding number of initial lines from the input.

    If skipblanks is true, blank lines in the input will be ignored.

    If use_mmap is true, the file specified by source is memory mapped for potential speedups. Default is true except on Windows. On Windows, you may want to specify true if the file is large, and is only read once and not written to.

    If quotes is true, columns enclosed within double-quote (“) characters are allowed to contain new lines and column delimiters. Double-quote characters within a quoted field must be escaped with another double-quote. Specifying dims as a tuple of the expected rows and columns (including header, if any) may speed up reading of large files. If comments is true, lines beginning with comment_char and text following comment_char in any line are ignored.

    Examples

    1. julia> using DelimitedFiles
    2. julia> x = [1; 2; 3; 4];
    3. julia> y = [5; 6; 7; 8];
    4. julia> open("delim_file.txt", "w") do io
    5. writedlm(io, [x y])
    6. end
    7. julia> readdlm("delim_file.txt", '\t', Int, '\n')
    8. 4×2 Matrix{Int64}:
    9. 2 6
    10. 3 7
    11. 4 8
    12. julia> rm("delim_file.txt")

    DelimitedFiles.readdlm — Method

    1. readdlm(source, delim::AbstractChar, eol::AbstractChar; options...)

    DelimitedFiles.readdlm — Method

    1. readdlm(source, delim::AbstractChar, T::Type; options...)

    The end of line delimiter is taken as \n.

    Examples

    DelimitedFiles.readdlm — Method

    1. readdlm(source, delim::AbstractChar; options...)

    The end of line delimiter is taken as \n. If all data is numeric, the result will be a numeric array. If some elements cannot be parsed as numbers, a heterogeneous array of numbers and strings is returned.

    Examples

    1. julia> using DelimitedFiles
    2. julia> y = [1.1; 2.2; 3.3; 4.4];
    3. julia> open("delim_file.txt", "w") do io
    4. writedlm(io, [x y], ',')
    5. end;
    6. julia> readdlm("delim_file.txt", ',')
    7. 4×2 Matrix{Float64}:
    8. 1.0 1.1
    9. 2.0 2.2
    10. 3.0 3.3
    11. 4.0 4.4
    12. julia> z = ["a"; "b"; "c"; "d"];
    13. julia> open("delim_file.txt", "w") do io
    14. writedlm(io, [x z], ',')
    15. end;
    16. julia> readdlm("delim_file.txt", ',')
    17. 4×2 Matrix{Any}:
    18. 1 "a"
    19. 4 "d"
    20. julia> rm("delim_file.txt")

    DelimitedFiles.readdlm — Method

    1. readdlm(source, T::Type; options...)

    Examples

    DelimitedFiles.readdlm — Method

    1. readdlm(source; options...)

    The columns are assumed to be separated by one or more whitespaces. The end of line delimiter is taken as \n. If all data is numeric, the result will be a numeric array. If some elements cannot be parsed as numbers, a heterogeneous array of numbers and strings is returned.

    Examples

    1. julia> using DelimitedFiles
    2. julia> x = [1; 2; 3; 4];
    3. julia> y = ["a"; "b"; "c"; "d"];
    4. julia> open("delim_file.txt", "w") do io
    5. writedlm(io, [x y])
    6. end;
    7. julia> readdlm("delim_file.txt")
    8. 4×2 Matrix{Any}:
    9. 1 "a"
    10. 2 "b"
    11. 3 "c"
    12. 4 "d"

    DelimitedFiles.writedlm — Function

    1. writedlm(f, A, delim='\t'; opts)

    Write A (a vector, matrix, or an iterable collection of iterable rows) as text to f (either a filename string or an IO stream) using the given delimiter delim (which defaults to tab, but can be any printable Julia object, typically a Char or AbstractString).

    For example, two vectors x and y of the same length can be written as two columns of tab-delimited text to f by either writedlm(f, [x y]) or by writedlm(f, zip(x, y)).

    Examples