# Loading .txt files into an array

**URL:** <https://discourse.julialang.org/t/loading-txt-files-into-an-array/41370>\
**Category:** VS Code\
**Tags:** question\
**Created:** [June 14, 2020, 1:05pm UTC](https://discourse.julialang.org/t/loading-txt-files-into-an-array/41370 "2020-06-14T13:05:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fathya.Salih](https://avatars.discourse-cdn.com/v4/letter/f/47e85d/32.png) [@Fathya.Salih](https://discourse.julialang.org/u/Fathya.Salih)\
**Post date:** [June 14, 2020, 1:05pm UTC](https://discourse.julialang.org/t/loading-txt-files-into-an-array/41370/1 "2020-06-14T13:05:25Z")

</div>

Hi there,  
I am having trouble using the function readdlm(“file path”) from DelimitedFiles in a vscode .jl tab. I have the following code structure:

```julia
# Test.jl

using DelimitedFiles
# function definitions
# Defining constants and initializing counters
Data = readdlm("Data_file") # the data file is in the same git directory as the .jl file

for i in 1:100000
    inputs = Data[i, 1]
    # call functions 
    # check conditions
    # increment appropriate counters
end

```

These functions run fine in the julia REPL on vscode, but the linter doesn’t recognise them and gives “missing reference” warnings.  
If I run w/o debugging, it takes a long time but it runs the readdlm() line and ends up breaking at a function in the for loop (The error message is as below).

```julia
ERROR: LoadError: MethodError: no method matching &(::Int64, ::Float64)
Closest candidates are:
  &(::Any, ::Any, ::Any, ::Any...) at operators.jl:529
  &(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:277
  &(::Integer) at operators.jl:506

```

When I start the debugger, it gets stuck at the readdlm() step and doesn’t get to the breakpoint I need a few lines after.

Is there a faster alternative to this function? Or some way to run the debugger with the variable “Data” defined from the REPL?

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [June 14, 2020, 5:38pm UTC](https://discourse.julialang.org/t/loading-txt-files-into-an-array/41370/2 "2020-06-14T17:38:36Z")

</div>

Welcome.

Let’s try to simplify things a bit. I don’t think there is enough info in your post to find a solution.

It’s easier to locate errors in functions (anyway a good idea). So, if you create, say, `test1.jl` with contents

```julia
function test1()
  Data = readdlm("Data_file")
  for j = 1 : 10
    println(Data[j, 1])
  end
end

```

then `include("test1.jl")` and run `test1()` from the REPL, does that give an error? Do the data look like they are read correctly?

If that runs, does it throw an error when you run the loop (without printing, of course) to 100\_000?

The error message that you posted looks truncated. It should give the line number where the error occurred (easier to interpret with the code inside a function).

---

<div class="post-metadata">

**Author:** ![Fathya.Salih](https://avatars.discourse-cdn.com/v4/letter/f/47e85d/32.png) [@Fathya.Salih](https://discourse.julialang.org/u/Fathya.Salih)\
**Post date:** [June 14, 2020, 5:55pm UTC](https://discourse.julialang.org/t/loading-txt-files-into-an-array/41370/3 "2020-06-14T17:55:35Z")

</div>

Hello! Thanks for responding.  
Since the time of posting this, I was able to get the entire code to run, but there are still some issues with the results. I’m expecting the problem to be in the use of local vs. global variables in for-loops. So I wanted a way to run the code line by line to find the source of the problem (Debugging still gets stuck at that same line). I am used to debugging that way from coding with Python.  
Is there a way to debug Julia line by line, or do you recommend going through suspected functions in separate test files?

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [June 14, 2020, 6:50pm UTC](https://discourse.julialang.org/t/loading-txt-files-into-an-array/41370/4 "2020-06-14T18:50:29Z")

</div>

There is a debugger, but I almost never use it. When I tried it a while ago, it was often very slow. Instead of debugging, I tend to load up my files with @assert statements to find where an error originates. Actually, more commonly, I run the code through tests which check everything I expect to be true until I find what is not.

If that fails, I just paste the code into the REPL and look. This works because I have tests set up which prepare inputs for the code that fails.

As for local / global variables in a loop: that is usually only an issue when the code is run outside of a function. So I would expect this not to be the source of your troubles.

---

<div class="post-metadata">

**Author:** ![Fathya.Salih](https://avatars.discourse-cdn.com/v4/letter/f/47e85d/32.png) [@Fathya.Salih](https://discourse.julialang.org/u/Fathya.Salih)\
**Post date:** [June 14, 2020, 7:04pm UTC](https://discourse.julialang.org/t/loading-txt-files-into-an-array/41370/5 "2020-06-14T19:04:28Z")

</div>

True. The debugger is very slow. I’ll try the methods you’ve mentioned here.

> [@hendri54](#):
>
> As for local / global variables in a loop: that is usually only an issue when the code is run outside of a function. So I would expect this not to be the source of your troubles.

I do have multiple for-loops outside of any function, as this used to be a python code for monte carlo simulations.

Thanks, again.
