# \[SOLVED\] Usage of CSV.read recently deprecated?

**URL:** https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129
**Category:** General Usage
**Created:** [December 2, 2020, 4:58pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129 "2020-12-02T16:58:38Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![danilo-bc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danilo-bc/32/19590_2.png) [@danilo-bc](https://discourse.julialang.org/u/danilo-bc)
#### Post date: [December 2, 2020, 4:58pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/1 "2020-12-02T16:58:38Z")

</div>

In 1 week, I used the following lines:

```nohighlight
using CSV: read
    In_vec = read(in_vec_file,header=false);
    In_vec = In_vec[1] #turn into usable Julia vector

```

They would return me an Array{Float64,1} of the size of my file. Now, after doing no changes, I get this error “ERROR: ArgumentError: provide a valid sink argument, like `using DataFrames; CSV.read(source, DataFrame)”

Did the functionality recently change? What is the easiest way to collect my ‘read’ as an Array? I know I can use DataFrames and Table.matrix to try to solve this, but I want to first understand the problem and second try to solve it without using more additional packages.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [December 2, 2020, 5:18pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/2 "2020-12-02T17:18:52Z")

</div>

If it’s just a super clean CSV file with Float64 values, you can use [`readdlm`](https://docs.julialang.org/en/v1/stdlib/DelimitedFiles/#Delimited-Files)

---

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [December 2, 2020, 5:24pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/3 "2020-12-02T17:24:01Z")

</div>

And even if the contents are not only numbers, `readdlm` will work too, only that it will produce an `Array{Any, 2}`.

---

<div class="post-metadata">

### Author: ![Wikunia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wikunia/32/2180_2.png) [@Wikunia](https://discourse.julialang.org/u/Wikunia)
#### Post date: [December 2, 2020, 5:31pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/4 "2020-12-02T17:31:33Z")

</div>

Have a look at `CSV.File` instead. I was wondering this as well yesterday.

---

<div class="post-metadata">

### Author: ![danilo-bc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danilo-bc/32/19590_2.png) [@danilo-bc](https://discourse.julialang.org/u/danilo-bc)
#### Post date: [December 2, 2020, 5:36pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/5 "2020-12-02T17:36:03Z")

</div>

So odd, but I’m glad I’m not the only one who noticed this issue.

@pdeffebach I’ll take a look at readdlm, but is there a way to keep using the same CSV.read structure with minimal changes?

---

<div class="post-metadata">

### Author: ![jonathanBieler](https://avatars.discourse-cdn.com/v4/letter/j/82dd89/32.png) [@jonathanBieler](https://discourse.julialang.org/u/jonathanBieler)
#### Post date: [December 2, 2020, 5:37pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/6 "2020-12-02T17:37:38Z")

</div>

You should be able to do `read(in_vec_file, DataFrame, header=false)` to get the previous behavior back. Apparently this was changed to avoid having DataFrames as a dependency in CSV.jl.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [December 2, 2020, 5:38pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/7 "2020-12-02T17:38:22Z")

</div>

Yeah, you can use

```julia
CSV.read(file, NamedTuple)

```

then work with the vector from that named tuple. You don’t even have to have DataFrames as a dependency for this.

---

<div class="post-metadata">

### Author: ![danilo-bc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danilo-bc/32/19590_2.png) [@danilo-bc](https://discourse.julialang.org/u/danilo-bc)
#### Post date: [December 2, 2020, 5:54pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/8 "2020-12-02T17:54:23Z")

</div>

Thanks @jonathanBieler and @pdeffebach for the inputs. Using DataFrame (which should have been 1:1 with my initial solution) requires changing `In_vec[1]` to `In_vec[!,1]` which is fine, but requires “`using DataFrames`”.

The solution with NamedTuple gives the exact behavior I had before, where I need to do `In_vec = In_vec[1] ` to get a usable vector.

I tried `In_vec = read(in_vec_file, collect, header=false)`, which is a bit frustrating because it’s _almost_ a one-liner. It outputs a 1-element Array{Any,1} similar to the NamedTuple method, requiring the second line to work.

I’m satisfied with this solution because, currently, I only have 1 data point per line. If I had multiple columns to be loaded at once (like a f(x,y) function dump), I think the NamedTuple method would give me a workable variable as well.

Only an ‘off-topic’ question remains: why doesn’t the [official documentation](https://csv.juliadata.org/stable/search/?q=csv.read) have a simple entry on CSV.read? Is it really deprecated and not intended for future use?

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [December 2, 2020, 5:57pm UTC](https://discourse.julialang.org/t/solved-usage-of-csv-read-recently-deprecated/51129/9 "2020-12-02T17:57:55Z")

</div>

I don’t know, I noticed that yesterday. It should be fixed.
