We can use the autodef'd config variable *cls-home-dir*, no need to hack an ugly...
[CommonLispStat.git] / examples / loading-data.lisp
blob07c664af688e831f28c9bc856304494e049c4e3a
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2010-01-14 07:55:00 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 (defun localized-pathto (x)
21 "return a string denoting the complete path.
22 FIXME: UNIX-centric (though might work on Mac OSX). Might want to
23 return a pathspec, not a string/namespec"
24 (check-type x string)
25 (concatenate 'string *cls-home-dir* x))
29 (progn
30 ;; FIXME: Need to clean up data examples, licenses, attributions, etc.
31 ;; The following breaks because we should use a package to hold
32 ;; configuration details, and this would be the only package outside
33 ;; of packages.lisp, as it holds the overall defsystem structure.
34 (load-data "iris.lsp") ;; (the above partially fixed).
35 (variables)
36 diabetes )
41 (progn
42 ;; Importing data from DSV text files.
44 (rsm.string:file->string-table
45 (localized-pathto "Data/example-mixed.csv"))
47 (rsm.string:file->number-table
48 (localized-pathto "Data/example-numeric.csv"))
51 (defparameter *my-df-2*
52 (make-instance 'dataframe-array
53 :storage
54 (listoflist:listoflist->array
55 (rsm.string:file->string-table
56 (localized-pathto "Data/example-mixed.csv")))
57 :doc "This is an interesting dataframe-array"))
58 *my-df-2*
61 (defparameter *my-df-3*
62 (make-instance 'dataframe-array
63 :storage
64 (listoflist:listoflist->array
65 (rsm.string:file->number-table
66 (localized-pathto "Data/example-numeric.csv")))
67 :doc "This is an interesting dataframe-array"))
68 *my-df-3*
70 ;; Need to the this using the make-dataframe example, or write a
71 ;; dsvfile->dataframe command.
74 (defparameter *tmp-csv-filedata* (rsm.string:file->number-table
75 (localized-pathto "Data/example-numeric.csv")))
76 (defparameter *tmp-csv-filedata* (rsm.string:file->number-table
77 (localized-pathto "Data/R-chickwts.csv")
78 :delims ","))
79 (defparameter *tmp-var-name-list* (car *tmp-csv-filedata*))
80 (defparameter *tmp-data-list* (cdr *tmp-csv-filedata*))
81 (defparameter *tmp-data-array* (listoflist:listoflist->array (cdr *tmp-csv-filedata*)))
82 (aref *tmp-data-array* 0 2)
83 (aref *tmp-data-array* 1 1)
84 (aref *tmp-data-array* 4 0)
86 (defparameter *test-df*
87 (let ((csv-file-data (rsm.string:file->number-table
88 (localized-pathto "Data/R-chickwts.csv")
89 :delims ",")))
90 (let ((var-name-list (car csv-file-data))
91 (data-list (listoflist:listoflist->array (cdr csv-file-data))))
92 (make-instance 'dataframe-array
93 :storage data-list
94 :var-labels var-name-list
95 :doc "This is an interesting dataframe-array"))))
97 *test-df*
100 (defparameter *testdf-2* (filename.dsv->dataframe (localized-pathto "Data/R-chickwts.csv")))
101 ;; *testdf-2*