1

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?

0dB
  • 675
  • 5
  • 13
  • Could you include a bit of `data` and an snip of the output in each case? – Arthur Ulfeldt Oct 30 '13 at 17:36
  • Hang on, I think I see what is happening: Incanter returns `incanter.core.Dataset` in the two-column example and `clojure.lang.LazySeq` in the one-column example. This reminds me of ["Why does Incanter return number instead of sequence when result is one value?"](http://stackoverflow.com/questions/16385215/). I can provide data if you still like, but maybe this already helps? – 0dB Oct 30 '13 at 17:44
  • Even minimal sample data will work, just use `(def data (dataset [:foo :bar] [[:a :b] [:c :d]]))`. – 0dB Oct 30 '13 at 17:52

2 Answers2

2

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 |
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
0

It sounds like you hit on the correct answer when you point out that in the single key case incanter simply returns a sequence. One way to get around this, though it could be a little less elegant is to simply request a second column and ignore the second result or put it into a sequence of maps after. Something only a little hackish like:

(map hash-map (repeat :key) result-seq)
Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284