Julia CSV.read stopped working

This is what I got:
_ _ ()_ | Documentation: https://docs.julialang.org
() | () () |
_ _ | | __ _ | Type “?” for help, “]?” for Pkg help.
| | | | | | |/ ` | |
| | |
| | | | (
| | | Version 1.6.5 (2021-12-19)
/ |_|||_’_| | Official https://julialang.org/ release
|__/ |

julia> using Pkg

julia> Pkg.activate(; temp = true)
Activating new environment at /var/folders/s1/mfq8vx4d63539vgg51kjcms00000gn/T/jl_QI8qVL/Project.toml

julia> Pkg.add([“CSV”, “DataFrames”])
Updating registry at ~/.julia/registries/General
Resolving package versions…
Updating /private/var/folders/s1/mfq8vx4d63539vgg51kjcms00000gn/T/jl_QI8qVL/Project.toml
[336ed68f] + CSV v0.10.4
[a93c6f00] + DataFrames v1.3.3
Updating /private/var/folders/s1/mfq8vx4d63539vgg51kjcms00000gn/T/jl_QI8qVL/Manifest.toml
[336ed68f] + CSV v0.10.4
[944b1d66] + CodecZlib v0.7.0
[34da2185] + Compat v3.43.0
[a8cc5b0e] + Crayons v4.1.1
[9a962f9c] + DataAPI v1.10.0
[a93c6f00] + DataFrames v1.3.3
[864edb3b] + DataStructures v0.18.11
[e2d170a0] + DataValueInterfaces v1.0.0
[48062228] + FilePathsBase v0.9.18
[59287772] + Formatting v0.4.2
[842dd82b] + InlineStrings v1.1.2
[41ab1584] + InvertedIndices v1.1.0
[82899510] + IteratorInterfaceExtensions v1.0.0
[e1d29d7a] + Missings v1.0.2
[bac558e1] + OrderedCollections v1.4.1
[69de0a69] + Parsers v2.3.1
[2dfb63ee] + PooledArrays v1.4.1
[08abe8d2] + PrettyTables v1.3.1
[189a3867] + Reexport v1.2.2
[91c51154] + SentinelArrays v1.3.12
[a2af1166] + SortingAlgorithms v1.0.1
[3783bdb8] + TableTraits v1.0.1
[bd369af6] + Tables v1.7.0
[3bb67fe8] + TranscodingStreams v0.9.6
[ea10d353] + WeakRefStrings v1.4.2
[0dad84c5] + ArgTools
[56f22d72] + Artifacts
[2a0f44e3] + Base64
[ade2ca70] + Dates
[8bb1440f] + DelimitedFiles
[8ba89e20] + Distributed
[f43a241f] + Downloads
[9fa8497b] + Future
[b77e0a4c] + InteractiveUtils
[b27032c2] + LibCURL
[76f85450] + LibGit2
[8f399da3] + Libdl
[37e2e46d] + LinearAlgebra
[56ddb016] + Logging
[d6f4376e] + Markdown
[a63ad114] + Mmap
[ca575930] + NetworkOptions
[44cfe95a] + Pkg
[de0858da] + Printf
[3fa0cd96] + REPL
[9a3f8284] + Random
[ea8e919c] + SHA
[9e88b42a] + Serialization
[1a1011a3] + SharedArrays
[6462fe0b] + Sockets
[2f01184e] + SparseArrays
[10745b16] + Statistics
[fa267f1f] + TOML
[a4e569a6] + Tar
[8dfed614] + Test
[cf7118a7] + UUIDs
[4ec0a83e] + Unicode
[deac9b47] + LibCURL_jll
[29816b5a] + LibSSH2_jll
[c8ffd9c3] + MbedTLS_jll
[14a3606d] + MozillaCACerts_jll
[83775a58] + Zlib_jll
[8e850ede] + nghttp2_jll
[3f19e933] + p7zip_jll
Precompiling project…
5 dependencies successfully precompiled in 4 seconds (23 already precompiled)

julia> using CSV, DataFrames

julia> CSV.read(“ICloud Drive/Desktop/Werk/Sydney/Ospats-plus/+RegrEst/Code+RegrEst/Codes Ospats-plus/NowleyT.txt”, DataFrame; delim = ‘,’, header = false)
ERROR: ArgumentError: “ICloud Drive/Desktop/Werk/Sydney/Ospats-plus/+RegrEst/Code+RegrEst/Codes Ospats-plus/NowleyT.txt” is not a valid file or doesn’t exist
Stacktrace:
[1] CSV.Context(source::CSV.Arg, header::CSV.Arg, normalizenames::CSV.Arg, datarow::CSV.Arg, skipto::CSV.Arg, footerskip::CSV.Arg, transpose::CSV.Arg, comment::CSV.Arg, ignoreemptyrows::CSV.Arg, ignoreemptylines::CSV.Arg, select::CSV.Arg, drop::CSV.Arg, limit::CSV.Arg, buffer_in_memory::CSV.Arg, threaded::CSV.Arg, ntasks::CSV.Arg, tasks::CSV.Arg, rows_to_check::CSV.Arg, lines_to_check::CSV.Arg, missingstrings::CSV.Arg, missingstring::CSV.Arg, delim::CSV.Arg, ignorerepeated::CSV.Arg, quoted::CSV.Arg, quotechar::CSV.Arg, openquotechar::CSV.Arg, closequotechar::CSV.Arg, escapechar::CSV.Arg, dateformat::CSV.Arg, dateformats::CSV.Arg, decimal::CSV.Arg, truestrings::CSV.Arg, falsestrings::CSV.Arg, stripwhitespace::CSV.Arg, type::CSV.Arg, types::CSV.Arg, typemap::CSV.Arg, pool::CSV.Arg, downcast::CSV.Arg, lazystrings::CSV.Arg, stringtype::CSV.Arg, strict::CSV.Arg, silencewarnings::CSV.Arg, maxwarnings::CSV.Arg, debug::CSV.Arg, parsingdebug::CSV.Arg, validate::CSV.Arg, streaming::CSV.Arg)
@ CSV ~/.julia/packages/CSV/jFiCn/src/context.jl:236
[2] #File#25
@ ~/.julia/packages/CSV/jFiCn/src/file.jl:221 [inlined]
[3] read(source::String, sink::Type; copycols::Bool, kwargs::Base.Iterators.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:delim, :header), Tuple{Char, Bool}}})
@ CSV ~/.julia/packages/CSV/jFiCn/src/CSV.jl:91
[4] top-level scope
@ REPL[5]:1

julia>

Okay, so the file path is incorrect. Can you cd into the directory in which the file is located and just do CSV.read("NowleyT.txt", DataFrame; delim = ',', header = false)?

What do you mean with “cd into the directory”?

Do help in the REPL on “cd”, and you will get the idea.

1 Like

I mean use the cd function to move to the directory that holds your file:

julia> pwd()
"/home/nils"

julia> cd("/home/nils/Documents")

julia> pwd()
"/home/nils/Documents"

pwd() tells you which directory you’re in, cd lets you switch directories.

This is what I did and got: julia> cd(“Codes Ospats-plus”)

julia> pwd()

“/Users/jjdegruijter/Desktop/Werk/Sydney/Ospats-plus/+RegrEst/code +RegrEst/Codes Ospats-plus”

julia> CSV.read(“NowleyT.txt”, DataFrame; delim = ‘,’, header =false)

ERROR: UndefVarError: CSV not defined

Stacktrace:

[1] top-level scope

@ REPL[16]:1

but have you done using CSV in the same session?

julia> using CSV

julia> CSV.read(“NowleyT.txt”, DataFrame; delim = ‘,’, header =false)

ERROR: UndefVarError: DataFrame not defined

Stacktrace:

[1] top-level scope

@ REPL[18]:1

julia> CSV.read(“NowleyT.txt”, DataFrames; delim = ‘,’, header =false)

ERROR: UndefVarError: DataFrames not defined

Stacktrace:

[1] top-level scope

@ REPL[19]:1

julia> using DataFrames

julia> CSV.read(“NowleyT.txt”, DataFrames; delim = ‘,’, header =false)

ERROR: MethodError: objects of type Module are not callable

Stacktrace:

[1] |>( x::Tables.CopiedColumns{CSV.File}, f::Module )

@ Base ./operators.jl:858

[2] read( source::String, sink::Module; copycols::Bool, kwargs::Base.Iterators.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:delim, :header), Tuple{Char, Bool}}} )

@ CSV ~/.julia/packages/CSV/0Elut/src/CSV.jl:91

[3] top-level scope

@ REPL[21]:1

You need using CSV and using DataFrames.

It seems you should read more tutorials to understand how package management works. And how to use Julia more broadly. I get the sense you are frequently starting new sessions and assuming things will start back where you left off. This is not the case. You need to re-run the startup code Nils gave you every time you start a new session in order to re-produce your problem.

4 Likes

While I completely agree with Peter, can you do the following:

  1. Copy the NowleyT.txt into the “Codes Ospats-plus” folder using your operating system’s file explorer

  2. Start a new Julia session.

  3. Run:

cd("Codes Ospats-plus")
pwd()
@assert isfile("NowleyT.txt")
using Pkg; Pkg.add(["CSV", "DataFrames"])
using CSV, DataFrames
CSV.read("NowleyT.txt", DataFrame; delim = `,`, header = false)

I did what Nils told me to do, and HOERA! This is what I got:

julia> cd(“Codes Ospats-plus”)

julia> pwd()
“/Users/jjdegruijter/Desktop/Werk/Sydney/Ospats-plus/+RegrEst/code +RegrEst/Codes Ospats-plus”

julia> @assert isfile(“NowleyT.txt”)

julia> using Pkg; Pkg.add([“CSV”, “DataFrames”])
Updating registry at ~/.julia/registries/General
Resolving package versions…
No Changes to ~/.julia/environments/v1.6/Project.toml
No Changes to ~/.julia/environments/v1.6/Manifest.toml

julia> using CSV, DataFrames

julia> CSV.read(“NowleyT.txt”, DataFrame; delim = ‘,’, header = false)
30×5 DataFrame
RowColumn1 Column2 Column3 Column4 Column5
│ Float64 Float64 Int64 Float64 Float64
─────┼───────────────────────────────────────────────────
1 │ 1.51181e6 -3.6314e6 134 14.0385 1.58793
2 │ 1.51188e6 -3.6314e6 135 14.0623 1.63998
3 │ 1.51196e6 -3.6314e6 136 13.8402 1.48364
4 │ 1.51173e6 -3.63148e6 248 14.308 1.81295
5 │ 1.51181e6 -3.63148e6 249 14.271 1.7802
6 │ 1.51188e6 -3.63148e6 250 14.2896 1.79292
7 │ 1.51196e6 -3.63148e6 251 13.9846 1.55426
8 │ 1.51203e6 -3.63148e6 252 13.1979 1.12702
⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮
24 │ 1.51256e6 -3.63155e6 374 11.035 1.17459
25 │ 1.51263e6 -3.63155e6 375 11.3989 1.40901
26 │ 1.51271e6 -3.63155e6 376 11.6166 1.72427
27 │ 1.51166e6 -3.63163e6 477 12.962 1.01452
28 │ 1.51173e6 -3.63163e6 478 13.1085 1.26399
29 │ 1.51181e6 -3.63163e6 479 14.3835 2.01886
30 │ 1.51188e6 -3.63163e6 480 14.8844 2.29299
15 rows omitted

2 Likes

Thank you very much for your help and all your patience!

1 Like

Glad this worked! Doesn’t really solve the original mystery of why instead of error messages you were shown the content of the file in which the error occurred, but if that happens again please start a new thread.