Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Revisited : Loading first few lines from data file

$
0
0

I am revisiting a question I had asked earlier, but none of the solutions work on my 1.1.0 version Julia. I have a data file with 100 rows of data of the form

1 2
3 4
5 6.1
...

I want to load the first few lines, say 10 of them, as a 10X2 array. Three solutions suggested to me are now yielding errors. I am at a loss on how to proceed. I do not want to read the entire file and then truncate the number of rows. I am listing below three methods that were suggested to me and also the error messages they create.

Method I : using head -n

julia> x = open(`head -n$100 $input_file`) do io
                  readdlm(io);
                         end;
ERROR: IOError: could not spawn `head -n100 Rot_golden_Complex_N=1E6_DeltaT=1E-2.txt`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at .\process.jl:400
 [2] setup_stdios(::getfield(Base, Symbol("##505#506")){Cmd}, ::Array{Any,1}) at .\process.jl:413
 [3] _spawn at .\process.jl:412 [inlined]
 [4] #open#514(::Bool, ::Bool, ::Function, ::Cmd, ::Base.DevNull) at .\process.jl:657
 [5] open at .\process.jl:648 [inlined] (repeats 2 times)
 [6] open(::getfield(Main, Symbol("##275#276")), ::Cmd) at .\process.jl:678
 [7] top-level scope at none:0

Method II : using *open( readlines …

julia> julia> x = open(readlines, `head -n10 $(input_file)`)
ERROR: IOError: could not spawn `head -n10 Rot_golden_Complex_N=1E6_DeltaT=1E-2.txt`: no such file or directory (ENOENT)
Stacktrace:
 [1] _spawn_primitive(::String, ::Cmd, ::Array{Any,1}) at .\process.jl:400
 [2] setup_stdios(::getfield(Base, Symbol("##505#506")){Cmd}, ::Array{Any,1}) at .\process.jl:413
 [3] _spawn at .\process.jl:412 [inlined]
 [4] #open#514(::Bool, ::Bool, ::Function, ::Cmd, ::Base.DevNull) at .\process.jl:657
 [5] open at .\process.jl:648 [inlined] (repeats 2 times)
 [6] open(::typeof(readlines), ::Cmd) at .\process.jl:678
 [7] top-level scope at none:0

Method III : using CSV package

julia> CSV.read("input_file", delim = ' ', rows = 10)
ERROR: MethodError: no method matching CSV.File(::String; delim=' ', rows=10)
Closest candidates are:
  CSV.File(::Any; header, normalizenames, datarow, skipto, footerskip, limit, transpose, comment, use_mmap, ignoreemptylines, threaded, select, drop, missingstrings, missingstring, delim, ignorerepeated, quotechar, openquotechar, closequotechar, escapechar, dateformat, decimal, truestrings, falsestrings, type, types, typemap, categorical, pool, strict, silencewarnings, debug, parsingdebug, allowmissing) at C:\Users\iamsu\.julia\packages\CSV\76SRf\src\CSV.jl:262 got unsupported keyword argument "rows"
Stacktrace:
 [1] kwerr(::NamedTuple{(:delim, :rows),Tuple{Char,Int64}}, ::Type, ::String) at .\error.jl:125
 [2] (::getfield(Core, Symbol("#kw#Type")))(::NamedTuple{(:delim, :rows),Tuple{Char,Int64}}, ::Type{CSV.File}, ::String) at .\none:0
 [3] #read#68(::Bool, ::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol},NamedTuple{(:delim, :rows),Tuple{Char,Int64}}}, ::Function, ::String) at C:\Users\iamsu\.julia\packages\CSV\76SRf\src\CSV.jl:1156
 [4] (::getfield(CSV, Symbol("#kw##read")))(::NamedTuple{(:delim, :rows),Tuple{Char,Int64}}, ::typeof(CSV.read), ::String) at .\none:0
 [5] top-level scope at none:0

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles