# Deprecated csv prefix

**URL:** https://discourse.julialang.org/t/deprecated-csv-prefix/7616
**Category:** Data
**Tags:** question, deprecation
**Created:** [December 8, 2017, 1:34am UTC](https://discourse.julialang.org/t/deprecated-csv-prefix/7616 "2017-12-08T01:34:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [December 8, 2017, 1:34am UTC](https://discourse.julialang.org/t/deprecated-csv-prefix/7616/1 "2017-12-08T01:34:25Z")

</div>

Hi,

Can you please clarify the newer syntax?

```julia
csv"""
x, y, z
1, 2, 3
"""

```

> @csv\_str and the csv"“” syntax are deprecated. Use CSV.read(IOBuffer(…)) from the CSV package instead.

Why the `csv` prefix was deprecated, couldn’t it be moved to CSV.jl instead?

---

<div class="post-metadata">

### Author: ![cjprybol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjprybol/32/2617_2.png) [@cjprybol](https://discourse.julialang.org/u/cjprybol)
#### Post date: [December 8, 2017, 3:39am UTC](https://discourse.julialang.org/t/deprecated-csv-prefix/7616/2 "2017-12-08T03:39:40Z")

</div>

We felt that the following (and variations of it) was a similarly straightforward and more general approach:

```julia
julia> using DataFrames, CSV

julia> csv = """
       x, y, z
       1, 2, 3
       """;

julia> CSV.read(IOBuffer(csv))
1×3 DataFrames.DataFrame
│ Row │ x │ y │ z │
├─────┼───┼───┼───┤
│ 1 │ 1 │ 2 │ 3 │

```

[That’s what was happening behind the scenes](https://github.com/JuliaData/DataFrames.jl/blob/master/src/deprecated.jl#L1115). But I think it was also because there was so much going on in preparation for the DataFrames 0.11 release nobody involved was able to prioritize it and take it on.

> couldn’t it be moved to CSV.jl instead?

Yes! If you’d like to prepare a PR to move it to CSV.jl, all of the relevant code is [here](https://github.com/JuliaData/DataFrames.jl/blob/master/src/deprecated.jl#L1089-L1272)

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [December 8, 2017, 3:45am UTC](https://discourse.julialang.org/t/deprecated-csv-prefix/7616/3 "2017-12-08T03:45:27Z")

</div>

Thank you @cjprybol, does the PR consist of copying the lines your highlighted into an appropriate place in CSV.jl or it needs further work? I am a little busy this weekend, but I can try look into it…

---

<div class="post-metadata">

### Author: ![NickNack](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicknack/32/1792_2.png) [@NickNack](https://discourse.julialang.org/u/NickNack)
#### Post date: [December 8, 2017, 4:45pm UTC](https://discourse.julialang.org/t/deprecated-csv-prefix/7616/4 "2017-12-08T16:45:02Z")

</div>

I never quite understood the point of the `csv"""` family of string macros in the first place for reading in-file tables of data. Since `Matrix{Any}` can hold arbitrary data types, why not use that instead? The main advantages are inline comments in the data tables and nice syntax highlighting in your editor.

Just add a simple helper function:

```julia
function array2dataframe(arr, header=true)
    if header
        DataFrame([[arr[2:end,i]...] for i=1:size(arr,2)], [arr[1,:]...])
    else
        DataFrame(arr)
    end
end

```

And then you can do this:

```julia
data = [
    :x :y :z
    1 2.0 "three" # Comments work ...
    4 5.0 "six" # ... and you get nice syntax highlighting in your editor
]

julia> df = array2dataframe(data)
2×3 DataFrames.DataFrame
│ Row │ x │ y │ z │
├─────┼───┼─────┼───────┤
│ 1 │ 1 │ 2.0 │ three │
│ 2 │ 4 │ 5.0 │ six │

```

Sorry for hijacking the topic to mention this but your question seemed answered already, and I think it would be great if DataFrames.jl (or CSV.jl) could have built-in support for reading tables in `Matrix{Any}`-format.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [December 8, 2017, 10:22pm UTC](https://discourse.julialang.org/t/deprecated-csv-prefix/7616/5 "2017-12-08T22:22:19Z")

</div>

Hi @NickNack, I think the main benefit of the string macro is for teaching or just quick example notebooks. There is no need to manually format the csv into a matrix with spaces and convert column names to symbols, etc.

The trick you shared is interesting anyways. Thanks.
