Saving using DelimitedFiled with header

On StockOverflow, I noticed a simple example of saving data to a delimited file:

x = [1 2 ; 3 4]
header = ["a" "b"]
writedlm(somefilepath, ',', [header ; x])

However, when I implement the code, all I get is a file with a comma. Has there been changes to Julia since the answer was posted (April 6., 2018), which renders the answer inappropriate?

I would generally recommend using CSV.jl for writing and reading CSV data, since that has a lot more features and performance optimizations than DelimitedFiles. The latter works fine, if you just want to quickly write or read some data, but for anything more advanced, CSV.jl is definitely the way to go

2 Likes

The documentation says that writedlm should look like this:
writedlm(f, A, delim='\t'; opts)

So if you use writedlm(somefilepath, [header ; x], ",") it should work.

This solution is also present in the stack overflow page.

1 Like