export filename.dsv->dataframe in the right place.
[CommonLispStat.git] / examples / loading-data.lisp
blob63b8419ed39759f2cce10f4f2002fbd2d9107c0e
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-12-21 12:29:49 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: template.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, LLGPL, or GPLv2, depending
8 ;;; on how it arrives.
9 ;;; Purpose: Template header file
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 ;; start within the common-lisp-stat-user
16 (in-package :cls-user)
18 ;; we'll be loading from directories in the CLS homedir, so we want to
19 ;; make it easier to reach.
20 (defparameter *my-cls-homedir*
21 "/home/tony/sandbox/CLS.git/" ; <- value with trailing directory separator
22 "documentation: change this to localize") ; <- doc
23 ;; so
24 (concatenate 'string *my-cls-homedir* "Data/example.csv")
25 ;; implies
26 (defun localized-pathto (x)
27 "return a string denoting the complete path.
28 FIXME: UNIX-centric (though might work on Mac OSX). Might want to
29 return a pathspec, not a string/namespec"
30 (check-type x string)
31 (concatenate 'string *my-cls-homedir* x))
35 (progn
36 ;; FIXME: Need to clean up data examples, licenses, attributions, etc.
37 ;; The following breaks because we should use a package to hold
38 ;; configuration details, and this would be the only package outside
39 ;; of packages.lisp, as it holds the overall defsystem structure.
40 (load-data "iris.lsp") ;; (the above partially fixed).
41 (variables)
42 diabetes )
47 (progn
48 ;; Importing data from DSV text files.
50 (rsm.string:file->string-table
51 (localized-pathto "Data/example-mixed.csv"))
53 (rsm.string:file->number-table
54 (localized-pathto "Data/example-numeric.csv"))
57 (defparameter *my-df-2*
58 (make-instance 'dataframe-array
59 :storage
60 (listoflist:listoflist->array
61 (rsm.string:file->string-table
62 (localized-pathto "Data/example-mixed.csv")))
63 :doc "This is an interesting dataframe-array"))
64 *my-df-2*
67 (defparameter *my-df-3*
68 (make-instance 'dataframe-array
69 :storage
70 (listoflist:listoflist->array
71 (rsm.string:file->number-table
72 (localized-pathto "Data/example-numeric.csv")))
73 :doc "This is an interesting dataframe-array"))
74 *my-df-3*
76 ;; Need to the this using the make-dataframe example, or write a
77 ;; dsvfile->dataframe command.
80 (defparameter *tmp-csv-filedata* (rsm.string:file->number-table
81 (localized-pathto "Data/example-numeric.csv")))
82 (defparameter *tmp-csv-filedata* (rsm.string:file->number-table
83 (localized-pathto "Data/R-chickwts.csv")
84 :delims ","))
85 (defparameter *tmp-var-name-list* (car *tmp-csv-filedata*))
86 (defparameter *tmp-data-list* (cdr *tmp-csv-filedata*))
87 (defparameter *tmp-data-array* (listoflist:listoflist->array (cdr *tmp-csv-filedata*)))
88 (aref *tmp-data-array* 0 2)
89 (aref *tmp-data-array* 1 1)
90 (aref *tmp-data-array* 4 0)
92 (defparameter *test-df*
93 (let ((csv-file-data (rsm.string:file->number-table
94 (localized-pathto "Data/R-chickwts.csv")
95 :delims ",")))
96 (let ((var-name-list (car csv-file-data))
97 (data-list (listoflist:listoflist->array (cdr csv-file-data))))
98 (make-instance 'dataframe-array
99 :storage data-list
100 :var-labels var-name-list
101 :doc "This is an interesting dataframe-array"))))
103 *test-df*
106 (defparameter *testdf-2* (filename.dsv->dataframe (localized-pathto "Data/R-chickwts.csv")))
107 ;; *testdf-2*