A Common Lisp port of the R readr package, designed to provide fast and friendly functions to read rectangular data (like CSV and TSV files) into cl-tibble data frames.
;; Load the system
(ql:quickload :cl-readr)
;; Read a CSV file into a tibble
(defparameter *df* (readr:read-csv "data.csv"))
;; View the tibble
(print *df*)
;; #<TIBBLE:TBL 150x5>
;; Access columns
(cl-tibble:tbl-col *df* "Sepal.Length")
;; Read with options
(readr:read-csv "data.csv" :skip 1 :col-names '("A" "B" "C"))
;; Write back to CSV
(readr:write-csv *df* "output.csv")-
Tibble Integration: All read functions return
cl-tibbleobjects, integrating seamlessly with thecl-tidyverseecosystem. -
Rectangular Data Parsing: Supports CSV, TSV, and custom delimiters.
-
Type Inference: Automatically guesses column types (Integer, Double, Logical, Character) based on content.
-
Robust Options: Supports skipping lines, comments (
#), max rows (n-max), and handling missing values (NA). -
Writing: Functions to write tibbles back to CSV or TSV.
cl-readr is part of the cl-tidyverse suite. Ensure you have the following dependencies available:
-
cl-tibble -
cl-vctrs-lite -
cl-ppcre -
local-time -
alexandria
Clone the repository to your local-projects directory:
cd ~/common-lisp/
git clone https://github.com/your-username/cl-readr.gitThen load via Quicklisp:
(ql:quickload :cl-readr)The package nickname is readr.
Reads a comma-separated values (CSV) file.
file: Path to the file.col-names:T(default) to read header from first row.NILto generate names. A list of strings to supply names manually.skip: Number of lines to skip before reading.n-max: Maximum number of data rows to read.comment: A string (e.g., "#") that indicates the start of a comment line.skip-empty-rows: If true (default), skip empty lines.
Reads a tab-separated values (TSV) file. Same arguments as read-csv.
Reads a file with a custom delimiter.
delim: The character used to separate fields (e.g.|).
Writes a tibble x to a CSV file.
delim: Delimiter to use (default,).na: String to use for missing values (default "NA").append: If true, append to the file instead of overwriting.col-names: If true (default), write headers.
Writes a tibble x to a TSV file.
Reads an entire file into a string.
Reads a file into a list of strings (lines).
MIT License.