clojureincanter

Why does Incanter lose column title when only querying one column?


When selecting two columns from a dataset, the result has the two given column titles as expected. But when only specifying one column, the one resulting column loses it's title, instead, it is titled "0":

This makes it hard to use $order or whatever in later steps that take column names.

That is, this will work

(with-data data   
  (->> ($ [:foo :bar])
       ($order [:foo] :asc)
       (view)))

and this will fail

(with-data data
  (->> ($ [:foo])
       ($order [:foo] :asc)
       (view)))

Any ideas what is going wrong or what to do?


Solution

  • which version of Incanter are you using? This behavior was changed in recent versions, and at least 1.5.4 works correctly. But take into account that behavior of $ is different when you pass the column name as single element, and as vector:

    incanter.main=> (def data (dataset [:foo :bar] [[:a :b] [:c :d]]))
    #'incanter.main/data
    incanter.main=> ($ :foo data)
    (:a :c)
    incanter.main=> ($ [:foo] data)
    
    | :foo |
    |------|
    |   :a |
    |   :c |