# Julia Support for File Loading

**URL:** <https://discourse.julialang.org/t/julia-support-for-file-loading/8673>\
**Category:** Data\
**Created:** [January 29, 2018, 3:53pm UTC](https://discourse.julialang.org/t/julia-support-for-file-loading/8673 "2018-01-29T15:53:52Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 29, 2018, 4:25pm UTC](https://discourse.julialang.org/t/julia-support-for-file-loading/8673/3 "2018-01-29T16:25:51Z")

</div>

Julia is perfectly capable of parsing this in a few lines of code without any special library (you read lines, extract fields, parse them). Eg with something like

```julia
using Missings

null_to_missing(x) = isnull(x) ? missing : unsafe_get(x)
parsefield(::Type{Int}, string) = null_to_missing(tryparse(Int, string))
parsefield(::Type{String}, string) = copy(string)
parsefield(df::DateFormat, string) = null_to_missing(tryparse(Date, string, df))

```

then iterating on

```julia
colspecs = (1:12 => Int,
            13:32 => String,
            33:40 => DateFormat("yyyymmdd"))

```

You can filter for missing values (which literally could be anything in these kinds of datasets), use generated functions for iteration, etc.

The difficult part is establishing the field boundaries. There is no reliable algorithmic way to do this, so these kind of files usually come with specs. If you are unlucky, it is a scan of a bunch of typewritten pages from the 1970s. If you are a bit more lucky, it is something semi-standard like DDF. You may find [this topic](https://discourse.julialang.org/t/is-there-no-standard-way-to-read-files-with-fixed-width-columns-in-the-new-dataframes-ecosystem/7324/3) and the one linked there useful.

Reading in column specs formats would be a great addition to the ecosystem. The abovementioned DDF is used in social sciences, I am sure other fields have their own formats. R seems to support some of these.

---

_[View the full topic](https://discourse.julialang.org/t/julia-support-for-file-loading/8673)._
