Permalink
Browse files

Added ability to use keywords, in addition to strings, to identify co…

…lumn names of a dataset to select using the :cols option of the sel method.
  • Loading branch information...
1 parent dfde00b commit 4b39d8e9f953f0a18cdda6115c612065d81019b8 @liebke liebke committed Dec 22, 2009
Showing with 15 additions and 7 deletions.
  1. +4 −2 pom.xml
  2. +11 −5 src/main/clojure/incanter/core.clj
View
@@ -18,13 +18,15 @@
<testScript>src/test/clojure/incanter/mvn_tests.clj</testScript>
</configuration>
<executions>
-<!-- <execution>
+ <!--
+ <execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
- </execution>-->
+ </execution>
+ -->
<execution>
<id>test</id>
<phase>test</phase>
@@ -231,8 +231,11 @@
(use 'incanter.datasets)
(def us-arrests (get-dataset :us-arrests))
(sel us-arrests :cols \"State\")
+ (sel us-arrests :cols :State)
(sel us-arrests :cols [\"State\" \"Murder\"])
+ (sel us-arrests :cols [:State :Murder])
+
"
(fn [mat & options] [(type mat) (keyword? (first options))]))
@@ -1119,11 +1122,14 @@
(defn- get-column-id [dataset column-key]
(let [headers (:column-names dataset)
- id (if (number? column-key)
- (if (some #(= column-key %) headers)
- column-key
- (nth headers column-key))
- column-key)]
+ col-key (if (keyword? column-key)
+ (name column-key)
+ column-key)
+ id (if (number? col-key)
+ (if (some #(= col-key %) headers)
+ col-key
+ (nth headers col-key))
+ col-key)]
id))

0 comments on commit 4b39d8e

Please sign in to comment.