Using Incanter and Clojure Soup together

288 views Asked by At

I am learning Clojure - it's a lot of fun! I am trying to use Incanter and Clojure Soup in the same file:

(require '[jsoup.soup :as soup])
(use '(incanter core stats io charts datasets))

And I get the following error:

CompilerException java.lang.IllegalStateException: $ already refers to: #'jsoup.soup/$ in namespace: user, compiling

I think I understand why, but how can I solve this problem? Appreciate this website and all the gurus on it!

Thanks.

1

There are 1 answers

0
Arthur Ulfeldt On BEST ANSWER

If you only actually use one of the $ functions then you can exclude the other one

(ns myproject.example
   (:require [jsoup.soup :as soup]
             [incanter [core :refer :all :exclude [$]]
                       [stats :refer :all] 
                       [io :refer :all] 
                       [charts :refer :all] 
                       [datasets :refer :all]]))

or you can take the approach of explicitly naming the vars you want to refer to in your namespace and explicitly calling the others by namespace-alias/function, which would look more like this:

(ns myproject.example
   (:require [jsoup.soup :as soup]
             [incanter [core :refer [$ ... and others here ...] 
                             :as incanter]
                       [stats :as stats] 
                       [io :as io] 
                       [charts :as charts] 
                       [datasets :as dataset]]))

The use method of using other namespaces is discouraged in modern clojure code and has been subsumed by the refer form, so I use that form in these examples. It's also strongly encouraged to put the refer forms in the namespace declaration.