Loading .txt files into an array

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:

# 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).

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?

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

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).

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?

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.

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

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

Thanks, again.