JonyEpsilon / gorilla-repl

A rich REPL for Clojure in the notebook style.
http://gorilla-repl.org
MIT License
887 stars 104 forks source link

gorilla + emacs - workflow for data analysis and exploration? #278

Open joefromct opened 7 years ago

joefromct commented 7 years ago

Hi, I've been reading through issues/docs and I'm not sure if what I'm searching for is possible; apologies if this is redundant or obvious to folks more familiar with gorilla-repl.

My use case:

I'm familiar with lein, namespaces, (n)repl's, cider, etc, I typically do data-processing coding with clojure (and other tools). I use python also but greatly prefer clojure (and everything with the jvm..).

Now I need to do some data analysis, exploration, and profiling... I want to use my customized emacs environment and would love to use clojure with output to gorilla repl.

Is there a way to edit in emacs, and somehow invoke my output to shoot out to the gorillla repl browser?

Gorilla's repl and plotting would be a huge upgrade over clojure.pprint for data analysis work.

I'm guessing folks are doing this... Did I miss something?

any tips appreciated, thanks in advance, -Joe

joefromct commented 7 years ago

FYI, here's some code I'm playing around with, after i cider-connect from within emacs.

(ns ff-datascience.core
    (:require [gorilla-plot.core :as plot]
              [gorilla-repl.table :as table]
              [clojure.data.csv :as csv]
              [clojure.java.io :as io]))

(def fantasy-football-data-2014  "http://www.repole.com/sun4cast/stats/nfl2014stats.csv")

(def sample-data
  (with-open [reader (io/reader fantasy-football-data-2014)]
    (doall
     (csv/read-csv reader))))

(table/table-view (take 3 t))

;; how do i get this to go to a pretty browser window?
;; #gorilla_repl.table.TableView{
;;                               :contents (
;;                                          ["Date" "TeamName" "ScoreOff" "FirstDownOff" "ThirdDownPctOff" "RushAttOff" "RushYdsOff" "PassAttOff" "PassCompOff" "PassYdsOff" "PassIntOff" "FumblesOff" "SackNumOff" "SackYdsOff" "PenYdsOff" "TimePossOff" "PuntAvgOff" "Opponent" "ScoreDef" "FirstDownDef" "ThirdDownPctDef" "RushAttDef" "RushYdsDef" "PassAttDef" "PassCompDef" "PassYdsDef" "PassIntDef" "FumblesDef" "SackNumDef" "SackYdsDef" "PenYdsDef" "TimePossDef" "Site" "Line" "TotalLine"]
;;                                          ["09/04/2014" "Green Bay Packers" "16" "19" "50%" "21" "80" "33" "23" "175" "1" "0" "3" "14" "65" "26:40" "38.3" "Seattle Seahawks" "36" "25" "36%" "37" "207" "28" "19" "191" "0" "1" "1" "0" "69" "33:20" "V" "-5.5" "46.5"]
;;                                          ["09/04/2014" "Seattle Seahawks" "36" "25" "36%" "37" "207" "28" "19" "191" "0" "1" "1" "0" "69" "33:20" "33.0" "Green Bay Packers" "16" "19" "50%" "21" "80" "33" "23" "175" "1" "0" "3" "14" "65" "26:40" "H" "5.5" "46.5"]
;;                                          ), :opts nil}

I have noticed if i manually go into the browser, switch the same namespace, and then table-view i can see things, but I'm trying to get my workflow just right and see if i can make gorilla my daily driver.

behrica commented 7 years ago

You might want to do it differently, namely having 2 namespaces. One ns which you edit in Emacs exclusively, which contains only some functions or defines global vars to get or manipulate the data.

The other name space gets edited only in Gorilla repl and it calls the functions from name space 1 and contains mainly visualisation code.

On each change of code in name space 1 , you re-evaluate the changed code inside, and then re-evaluate in gorilla the cells to see the change.

so in your case, the first 2 def's would live in one names space (edited by Emacs) and the (table-view ..) would live in teh Gorilla edited name space.

Probably you would do this gradualy. Starting in Gorilla only, and then when code becomes more stable, move it to the second name space. Like this you can handle the rather limited code edit features of Gorilla.