CSV.jl icon indicating copy to clipboard operation
CSV.jl copied to clipboard

Please provide a way to sink to a standard Matrix without Tables or Dataframes

Open sylvaticus opened this issue 3 years ago • 3 comments

Unless I am wrong (but if so, many are on the internet too) to sink to a standard Matrix one has to first using Tables.jl or DataFrames.jl. I believe it would be useful if CSV could be able to sink directly to a standard Matrix, e.g. foo= CSV.read("foo.csv", Matrix; [options])

I am aware of readdlm, but CSV has way more options.

sylvaticus avatar Oct 06 '22 14:10 sylvaticus

Hmmm, yeah, we could probably support this really easily by just wrapping/unwrapping the Tables.matrix call for you with a specific CSV.read dispatch for Matrix. I think that makes sense. We originally decided not to treat Matrix as a table in the Tables.jl interface sense because they don't really have column names/follow the other table properties, but I think this is a specific use-case where it's convenient to get a matrix out directly.

quinnj avatar Oct 06 '22 17:10 quinnj

Would this just be

CSV.read(source, ::Type{Matrix}; kw...) = CSV.read(source, Tables.matrix; kw...)

?

Would we want to allow people to write CSV.read("foo.csv", Matrix{Int}) (i'm not sure how we'd do that)... so perhaps we'd want to throw in that case and point users to CSV.read("foo.csv", Matrix)?

nickrobinson251 avatar Oct 06 '22 20:10 nickrobinson251

@nickrobinson251, yeah that was my idea. Yeah, on the error path, maybe we have a CSV.read(source; ::Type{<:AbstractMatrix}) that says we only support Matrix and to control types, pass types=Int or something?

quinnj avatar Oct 06 '22 22:10 quinnj