Liking cljdoc? Tell your friends :D

Clojask-io

A Clojure library designed to extend the file support for Clojask. This library can also be used alone to read in and output dataset files.

Installation

Available on Clojars: Clojars Project

APIs

NS: clojask-io.core

supports

Check if this library supports to read and write this format of file.

ArgumentTypeFunctionRemarks
formatStringIndicates the format of type, e.g. "csv", "xls", "txt", etc.

Return

Boolean


infer-format

Infer the file format from the path (get the substring after the last .).

ArgumentTypeFunctionRemarks
pathStringIndicates where to find the file (either on local machine or online)- For local files, absolute / relative path of the file
- For online resources, url of the resources

Return

String, such as "csv", "xls" (nil if fails to infer)


NS: clojask-io.input

read-file

Read in a file as lazy sequence. Optionally, provide size of the file, corresponding output functions.

Supported file types: csv, txt, dat, tsv, tab. The file size can be larger than memory.

ArgumentTypeFunctionRemarks
pathStringIndicates where to find the file (either on local machine or online)- For local files, absolute / relative path of the file
- For online resources, url of the resources
[format]StringThe format of the fileWill be inferred from the path suffix if not provided. Will imply the separator (sep) based on pre-setting.
[sep]String / java.util.regex.Pattern (regex)The separator of each row of the dataset file
[wrap]StringWrapper of each valueSometimes, the file will wrap each value some punctuations, e.g "" / ''. Can remove them automatically by setting this argument. Does not support asymmetric wrappers.
[stat]BooleanWhether to get the size of the fileIf true, the return value will add a :size key-value pair in unit of bytes. Size value will be nil if cannot be retrieved.
[output]BooleanWhether to also return the corresponding output functionIf true, the return value will add a :output key-value pair.

Return

{:data a lazy sequence of vectors representing each row :close 0-arity function that closes the underlying reader (only needed if :data is not fully consumed; consuming :data to the end closes it automatically) [:size the size in byte] [:output output function]}

read-excel

Read in an excel file as lazy sequence. Optionally, provide size of the file.

A simplified wrapper function of Docjure. The excel file should be smaller than memory size.

ArgumentTypeFunctionRemarks
pathStringIndicates where to find the file (either on local machine or online)- For local files, absolute / relative path of the file
- For online resources, url of the resources
sheetStringName of the sheet
[stat]BooleanWhether to get the size of the fileIf true, the return value will add a :size key-value pair in unit of bytes. Size value will be nil if cannot be retrieved.

Return

{:data a lazy sequence of vectors representing each row :close 0-arity no-op function (excel files are read eagerly; present for interface uniformity with read-file) [:size the size in byte]}


NS: clojask-io.output

write-csv

Synchronously write a collection of collections to a csv-like file.

ArgumentTypeFunctionRemarks
writerjava.io.BufferedWriterThe writer initialized to the output file
sequenceCollectionThe output contentShould a two-dimensional collection
separatorStringThe separator between values in the same row

Implementation

(defn write-csv
  "output to a csv file using a collection of collections"
  [writer seq sep]
  (doseq [row seq]
    (.write writer (str (str/join sep row) "\n"))
    ))

Return

nil


write-excel

Synchronously write a collection of collections to an excel file.

A simplified wrapper function of Docjure.

ArgumentTypeFunctionRemarks
pathStringIndicates the path of output fileAbsolute / relative path of local file system
sheetStringName of the sheet
sequenceCollectionThe output contentShould a two-dimensional collection

Return

nil


Copyright © 2022 Clojask-io

Can you improve this documentation? These fine people already did:
Yuchen Liu, Matt Buehlmaier & pilottam
Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close