DelimitedFiles.readdlm(source, ....) modifies source, is that really intended and where in the documentation/definition is this explained?

Viewed 291

surprised to find that DelimitedFiles.readdlm(source, ...) changes the source input parameter. surprised because Ι could find no indication hereof in the official documentation https://docs.julialang.org/en/v1/stdlib/DelimitedFiles/index.html. is this just a standard assumption about mutability in julia? i thought that somefunction that might change an input parameter would indicate this with somefunction! (adding ! to the function name)?

Ι used the function as follows:

out = DelimitedFiles.readdlm(source,',',header=true)

before the call, source has type Array{UInt8,1} and has several elements. after the call, out has type Tuple{Array{Any,2},Array{AbstractString,2}}, source has type Array{UInt8,1} (unchanged) and source is empty (changed).

1 Answers

The reason is that String(vec::Vector{UInt8}) does not perform a copy but takes ownership of vec (and mutates it).

For now you should write:

out = DelimitedFiles.readdlm(copy(source),',',header=true)

I have asked a question here to clarify what is the intended target behavior (copying or non-copying).

Related