# Readdlm command issue

**URL:** <https://discourse.julialang.org/t/readdlm-command-issue/45303>\
**Category:** New to Julia\
**Tags:** question, io\
**Created:** [August 21, 2020, 4:04am UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303 "2020-08-21T04:04:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnirudhBhaskar21](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@AnirudhBhaskar21](https://discourse.julialang.org/u/AnirudhBhaskar21)\
**Post date:** [August 21, 2020, 4:04am UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/1 "2020-08-21T04:04:04Z")

</div>

Im new to julia and im having this issue. Im using julia version 1.4.2 running on Jupyter.  
Code

> using LinearAlgebra,Plots  
> using DelimitedFiles,SparseArrays

# Retriving data in text file to an array

> y = readdlm(“data.txt”);

# Getting Length of array

> N = length(y);

# Creating ones vector of size Nx1

> e = ones(N,1);

# Creating SparseDaigonal matrix

> D = Matrix(spdiagm(N-2, N, 0 =\> ones(N-2), 1 =\> -2\*ones(N-2), 2 =\> ones(N-2)));

# Getting Variance

> Ty=(D_y)'_(D\*y)  
> println(Ty)

# Creating Identity matrix of size NxN

> Id = Matrix(I,N,N);

# Initalsing Lamda

> lam = 100;

# Getting x with help of analytical Solution

> x=(Id+lam\*D’\*D)\y;

# Getting Variance after removing noise

> Tx=(D_x)'_(D\*x);  
> println(Tx)

error:

> at row 0, column 0 : ArgumentError(“number of rows in dims must be \> 0, got 0”)  
> Stacktrace:  
> [1] error(::String) at .\error.jl:33  
> [2] dlm\_fill(::DataType, ::Array{Array{Int64,1},1}, ::Tuple{Int64,Int64}, ::Bool, ::String, ::Bool, ::Char) at D:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.4\DelimitedFiles\src\DelimitedFiles.jl:514  
> [3] readdlm\_string(::String, ::Char, ::Type, ::Char, ::Bool, ::Dict{Symbol,Union{Char, Integer, Tuple{Integer,Integer}}}) at D:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.4\DelimitedFiles\src\DelimitedFiles.jl:470  
> [4] readdlm\_auto(::String, ::Char, ::Type{T} where T, ::Char, ::Bool; opts::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at D:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.4\DelimitedFiles\src\DelimitedFiles.jl:246  
> [5] readdlm\_auto at D:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.4\DelimitedFiles\src\DelimitedFiles.jl:233 [inlined]  
> [6] #readdlm#5 at D:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.4\DelimitedFiles\src\DelimitedFiles.jl:170 [inlined]  
> [7] readdlm at D:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.4\DelimitedFiles\src\DelimitedFiles.jl:170 [inlined]  
> [8] #readdlm#3 at D:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.4\DelimitedFiles\src\DelimitedFiles.jl:118 [inlined]  
> [9] readdlm(::String) at D:\buildbot\worker\package\_win64\build\usr\share\julia\stdlib\v1.4\DelimitedFiles\src\DelimitedFiles.jl:118  
> [10] top-level scope at In[3]:4

---

<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:** [August 21, 2020, 6:07am UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/2 "2020-08-21T06:07:13Z")

</div>

Please follow these advices to post your questions:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

In particular:

1. Wrap the example code between ` ```julia` and ````` to make it readable in markdown.
2. Copy the output as text, avoid screenshots.

In this case, the problem seems to be that the file is not readable by`readdlm`. Can you copy the first couple of lines?

---

<div class="post-metadata">

**Author:** ![AnirudhBhaskar21](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@AnirudhBhaskar21](https://discourse.julialang.org/u/AnirudhBhaskar21)\
**Post date:** [August 21, 2020, 6:24am UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/4 "2020-08-21T06:24:40Z")

</div>

I am getting the same error. So is it a dependency issue?

---

<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:** [August 21, 2020, 8:26am UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/5 "2020-08-21T08:26:16Z")

</div>

Maybe I didn’t explain myself correctly: the advices I were commenting are for posting your example to the list and make it easier to help you, not for fixing the error.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 21, 2020, 8:56am UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/6 "2020-08-21T08:56:20Z")

</div>

This is pretty much impossible to debug, as your first line of code is `y = readdlm("data.txt")`, and everything follows from that - but it’s impossible for others to know what’s in `data.txt` and therefore what `y` ends up being.

Another point in the PSA was to create a minimum working example, that is a piece of code that someone else can copy/paste on their local computer and run to recreate your error. This will make it easier for others to work out what’s going wrong.

---

<div class="post-metadata">

**Author:** ![puerco-errante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/puerco-errante/32/19468_2.png) [@puerco-errante](https://discourse.julialang.org/u/puerco-errante)\
**Post date:** [January 10, 2022, 7:27pm UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/7 "2022-01-10T19:27:10Z")

</div>

I think this is the error one usually finds when the file to be read is actually empty. I landed here to see if there’s a nice way to deal with these exceptions. I suppose `try/catch` should be my friend, but if anyone has already thought about this I’d appreciate some help 🙂

---

<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:** [January 10, 2022, 7:49pm UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/8 "2022-01-10T19:49:36Z")

</div>

Also, the OP should consider updating to the latest Julia version, Julia v1.4 is considered old for Julia standards. We are currently in Julia v1.7.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [January 10, 2022, 7:58pm UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/9 "2022-01-10T19:58:23Z")

</div>

`try/catch` is probably the correct approach. You won’t be calling `readdlm` in a time-critical loop - so don’t worry about the error handling overhead.

If you want to be fancy about it, there’s always `CSV.jl`, which lets you do

```julia
julia> using CSV, DataFrames

julia> df = CSV.read("file.csv", DataFrame; header=["Name","Ranking","Score"], types=[String, Int64, Float64])
0×3 DataFrame

julia> df.Name
0-element PooledArrays.PooledVector{String, UInt32, Vector{UInt32}}

julia> push!(df, ("John", 24, 354.2))
1×3 DataFrame
 Row │ Name Ranking Score
     │ String Int64 Float64
─────┼──────────────────────────
   1 │ John 24 354.2

```

---

<div class="post-metadata">

**Author:** ![puerco-errante](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/puerco-errante/32/19468_2.png) [@puerco-errante](https://discourse.julialang.org/u/puerco-errante)\
**Post date:** [January 10, 2022, 9:24pm UTC](https://discourse.julialang.org/t/readdlm-command-issue/45303/10 "2022-01-10T21:24:21Z")

</div>

CSV is very fancy indeed! Thank you very much 🙂
