# File split/Dvector/lib/Dvector_extras.rb, line 61 def Dvector.fancy_read(stream, cols = nil, opts = {}) # :doc: o = FANCY_READ_DEFAULTS.dup o.update(opts) if stream.is_a?(String) stream = File.open(stream) end raise ArgumentError.new("'stream' should have a gets method") unless stream.respond_to? :gets o['sep'] = Regexp.new(o['sep']) unless o['sep'].is_a? Regexp res = Dvector.fast_fancy_read(stream, o) # Adding the index columns if necessary if o["index_col"] res.unshift(Dvector.new(res[0].length) { |i| i}) end if cols return cols.map {|i| res[i] } else return res end end