Question

I am trying to implement the following link http://data-sorcery.org/category/pca/ and found myself stuck trying to load the necessary Incanter libraries, i.e.

(use '(incanter core stats charts datasets))

The only dependency that I have for Incanter is [incanter "1.5.4"]. Is this enough to load the libraries, am I just missing something?

I am not really sure how to load the 4 highlighted libraries in the link. To note I have been able to use Incanter previously in the REPL.

Edit: My text editor has the following

(ns my-namespace.filename
(:use [incanter.core]
      [incanter.stats]
      [incanter.charts]
      [incanter.datasets]))


(def iris (to-matrix (get-dataset :iris))) 
(view iris)

which returns the error CompilerException javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name, compiling:(pca.clj:11:22)

The error seems to stem from the inner part, namely the get-dataset... which I am unsure how to fix.

Was it helpful?

Solution 2

Sometimes there is a confusion between the Incanter's libraries (that are included as dependencies) & Incanter's namespaces. One library can contain many namespaces, for example, incanter-core includes incanter.core, incanter.stats, etc., while the incanter.datasets is in the incanter-io library (together with incanter.io), and incanter.charts is in the incanter-charts library.

If you include the incanter as dependency in your project.clj, then it will include all libraries & namespaces provided by Incanter.

The Incanter was split into many libraries to decrease the number of dependencies for cases, when people want to use only small part of its functionality, for example, only incanter.stats + incanter.datasets.

Some information about Incanter's libraries you can find in the following presentation

Edited: The problem with SSL arises from the old bug when dataset always was downloaded from Internet. See this issue for details...

I've committed the fix 2 days ago, but it still only in the master, not released. To fix it in the release version, add following to your project.clj:

:jvm-opts ["-Djsse.enableSNIExtension=false"]

This will prevent the error. If you don't want to download the datasets from Internet, you can explicitly pass the path to them via get-dataset's options:

(get-dataset :iris :from-repo false 
              :incanter-home "/Users/ott/projects/incanter")

The :incanter-home path should point to the directory under which the Incanter's data folder is stored.

OTHER TIPS

Since you say you've been able to load dependencies from the REPL I assume you are now trying to load it from lein.

You need to include the dependency in your project.clj:

(defproject my-project "0.1.0-SNAPSHOT"
  :dependencies [[incanter "1.5.4"]])

At the top of the file where you want to use incanter functions have one of the following with the proper namespace and file name.

(ns my-namespace.filename
  (:require (incanter [core :refer :all]
                      [stats :refer :all]
                      [charts :refer :all]
                      [datasets :refer :all]))

This is the same as:

(ns my-namespace.filename
  (:require [incanter.core :refer :all]
            [incanter.stats :refer :all]
            [incanter.charts :refer :all]
            [incanter.datasets :refer :all]))

Same as:

(ns my-namespace.filename
  (:use [incanter.core]
        [incanter.stats]
        [incanter.charts]
        [incanter.datasets]))

I use the first variation for consistency since I usually don't want to :refer :all with all dependencies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top