Skip to content
Browse files

added cl-csv-data-table.asd, new package and function

 * added get-data-from-csv-list
 * use cl-csv:: for unexported cl-csv symbols
  • Loading branch information...
1 parent bc24112 commit 9f0e55c3e37d5de202f6065bc783fc7d58f91507 @slyrus slyrus committed Jun 12, 2012
Showing with 64 additions and 4 deletions.
  1. +38 −0 cl-csv-data-table.asd
  2. +26 −4 data-table.lisp
View
38 cl-csv-data-table.asd
@@ -0,0 +1,38 @@
+
+(asdf:defsystem :cl-csv-data-table
+ :description "Facilities for converting CSV data to data-tables"
+ :licence "BSD"
+ :version "0.1"
+ :components ((:file "data-table"))
+ :depends-on (:cl-csv :data-table))
+
+;; Copyright (c) 2012 Russ Tyndall , Acceleration.net http://www.acceleration.net
+;; -- This file contributed by Cyrus Harmon
+;; All rights reserved.
+;;
+;; Redistribution and use in source and binary forms, with or without
+;; modification, are permitted provided that the following conditions are
+;; met:
+;;
+;; - Redistributions of source code must retain the above copyright
+;; notice, this list of conditions and the following disclaimer.
+;;
+;; - Redistributions in binary form must reproduce the above copyright
+;; notice, this list of conditions and the following disclaimer in the
+;; documentation and/or other materials provided with the distribution.
+;;
+;; - Neither the name of Edward Marco Baringer, nor BESE, nor the names
+;; of its contributors may be used to endorse or promote products
+;; derived from this software without specific prior written permission.
+;;
+;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
30 data-table.lisp
@@ -1,14 +1,36 @@
-(in-package :cl-csv)
-(cl-interpol:enable-interpol-syntax)
+
+(cl:defpackage #:cl-csv-data-table
+ (:use :cl)
+ (:use :cl-csv)
+ (:export #:get-data-table-from-csv
+ #:get-data-table-from-list))
+
+(cl:in-package #:cl-csv-data-table)
(defun get-data-table-from-csv (file &optional (has-column-names t) (munge-types T) sample
&aux (dt (make-instance 'data-table:data-table)))
- (with-csv-input-stream (in-stream file)
+ (cl-csv::with-csv-input-stream (in-stream file)
(flet ((map-fn (row) (mapcar #'data-table::trim-and-nullify row)))
(when has-column-names
- (setf (data-table:column-names dt) (map-fn (read-csv-row in-stream))))
+ (setf (data-table:column-names dt) (map-fn (cl-csv::read-csv-row in-stream))))
(setf (data-table:rows dt)
(read-csv in-stream :map-fn #'map-fn :sample sample))
(when munge-types
(data-table:coerce-data-table-of-strings-to-types dt))
dt)))
+
+(defun get-data-table-from-csv-list
+ (list &optional (has-column-names t) (munge-types T) sample
+ &aux (dt (make-instance 'data-table:data-table)))
+ (flet ((map-fn (row) (mapcar #'data-table::trim-and-nullify row)))
+ (when has-column-names
+ (setf (data-table:column-names dt) (map-fn (first list))))
+ (setf (data-table:rows dt)
+ (mapcar (lambda (x)
+ (if sample
+ (map-fn (subseq x 0 sample))
+ (map-fn x)))
+ (rest list)))
+ (when munge-types
+ (data-table:coerce-data-table-of-strings-to-types dt))
+ dt))

0 comments on commit 9f0e55c

Please sign in to comment.
Something went wrong with that request. Please try again.