CSV.read() error please provide a valid sink argument

Hello I anm new here. I work through the real great book “Julia Quick syntax reference” from Antonello Lobianco. I typed a code from page 183. What is wrong with

d_table = CSV.read(IOBuffer(“”"
plants new-york chicago topeka
seattle 2.5 1.7 1.8
san-diego 2.5 1.8 1.4
“”“) , delim=” ", ignorerepeated=true, copycols=true)

The error when running is:

ArgumentError: provide a valid sink argument, like using DataFrames; CSV.read(source, DataFrame)

Apparently, it asks for a second argument “DataFrame” ??

Thanks for help
Tony

Hi Tony, welcome to the Julia community!
When was the book written?

CSV uses the Tables.jl convention now, which means that it only provides a “backend” for understanding CSVs and the “frontend” needs to be another Tables sink which determines what you get out on the Julia side. It’s really easy, DataFrames is a good default. But this mechanism allows you to read a CSV directly into a database for example, without ever creating an intermediate table.

Furthermore, you should always enclose your code in ` backticks.
So `print(“Hello world!”)` becomes print("Hello world!")

And using tripple ``` makes

```julia
d_table = CSV.read(IOBuffer(“”"
plants new-york chicago topeka
seattle 2.5 1.7 1.8
san-diego 2.5 1.8 1.4
“”“) , delim=” ", ignorerepeated=true, copycols=true)
```

Appear as:

d_table = CSV.read(IOBuffer("""
plants new-york chicago topeka
seattle 2.5 1.7 1.8
san-diego 2.5 1.8 1.4
""") , delim=" ", ignorerepeated=true, copycols=true)

What you asked for is this:

julia>  d_table = CSV.read(IOBuffer("""
        plants new-york chicago topeka
       seattle 2.5 1.7 1.8
       san-diego 2.5 1.8 1.4"""), DataFrame, delim=" ", ignorerepeated=true, copycols=true)
2×4 DataFrame
 Row │ plants     new-york  chicago  topeka
     │ String     Float64   Float64  Float64
─────┼───────────────────────────────────────
   1 │ seattle         2.5      1.7      1.8
   2 │ san-diego       2.5      1.8      1.4

Hi FPGro,

Great, thank you. It worked right away. Well, the book is from 2019. Thanks also for your kind advise on how to post code.
Tony

Regarding Antonello Lobianco’ s book you may also be interested in checking this out.