kstIO

Content

Introduction

The current functionality of kstIO stems from two developmental processes: - File formats: Earlier (pre--R) software developments used various ASCII and binary file formats developed over time. Later, kstIO was extended to allow also for spreadsheet formats (CSV, ODS, and XLSX). - R package development There are two general R packages on knowledge space theory, kst and kstMatrix. The former uses sets and relations as representation, the latter uses matrices. The hope behind developing kstMatrix was that matrices as native data type in R might be processed faster than sets.

kstIO was originally developed to offer I/O functions supporting the kst package and later extended to support also the meanwhile created kstMatrixpackage and its data object classes.

File formats

Classical ASCII file formats

The aforementioned binary file formats are not (and probably never will be) supported by kstIO. The ASCII formats are fully supported; they come in three different forms, each expanding the previous one by additional header lines containing meta information. - Matrix form: The matrix format files consist simply of a binary matrix, one row per knowledge state (or response pattern) and per--item columns. A cell contains a 1 if the respective item is element of the respective knowledge state, and a 0 otherwise. - KST form: The Matrix is simply preceded by two header lines containing the number of items and the number of knowledge states (or response patterns). - SRBT form: This form was developed in a project on surmise relations between tests (therefore the name). It expands the KST form by yet another preceding header line with information about the file content (e.g., basis, space, relation) and the storage format (ASCII vs. binary).

Spreadsheet formats

The more recent spreadsheet formats comprise three types: CSV (comma-separated values), ODS (Open Document Spreadsheet, e.g. by LibreOffice or OpenOffice), and XLSX (Microsoft Excel). All kstIO I/O functions support all three spreadsheet types.

The spreadsheet tables have the same form in all three formats (CSV, ODS, and XHTML). They typically (exceptions are, e.g., surmise functions; see below) start with a header line containing the item names followed by the binary matrix as described above for the ASCII files. Surmise and attribution functions have an additional preceding column containing the name of the item for which the respective matrix row describes a clause.

Supported data structures

Both basic KST packages, kst and kstMatrix, use hierarchies of R classes. Class names in kst start with a 'k', those in kstmatrix with a 'km'. In principle, if an object belongs to some class, the kst and kstMatrix functions assume that it fulfills the conditions of that class.

kstMatrix classes

The subsequent figure (from the kstMatrix vignette) shows the class hierarchy in that package. It means, e.g., that kmqspace is a sub-class of kmspace which is a sub-class of kmstructure which again is a sub-class of kmfamset.

Figure 1: kstMatrixclass hierarchy

List of kstMatrix classes

kst classes

The class hierarchy of kst is very similar, basically it is a subset because some functionality (and therefore several classes) have been developed (or defined, respectively) in kstMatrix only. While kstMatrix class-names start with 'km', the kst class-names start with a simple 'k'.

{width=350}
Figure 2: kst class hierarchy

Functionality and default parameters

For most of the data types shown in Figures 1 & 2, there are reading and writing functions as listed below. Exceptions to this are quasi--ordinal knowledge spaces (kmqspace class) and neighbourhoods (kmneighbourhood class).

Function list

Reading functions

^1^These functions return a list with two elements, matrix and sets, containing the loaded data in the respective form. ^2^These functions return the respective data as kstMatrix class object as there is no corresponding kst class.

Writing functions

These functions accept kst and kstMatrix data objects.

One might consider to integrate the write functions into one S3 class. However, for technical reasons this would not work for the read functions.

Utilities

There are two utility functions mapping between set and matrix representations. These functions do not respect the classes assigned to the objects which are to be mapped. - as.binaryMatrix - as.famset

Function parameters

There are numerous parameters shared by most of the reading and writing functions.

Mandatory parameters

Optional parameters

Please note that not all optional parameters are supported by all functions. For example, there are no properties to be enforced with kmdata objects.

Examples

For the following examples, we use the xpl basis from the kstMatrix package just because the object and the resulting files are small.

Setup

We start with some setup: importing libraries and defining filenames:

library(kstIO)
library(kstMatrix)
csvname <- paste0(tempdir(), "/xpl_bas.csv")
odsname <- paste0(tempdir(), "/xpl_bas.ods")
srbtname <- paste0(tempdir(), "/xpl.bas")

The xpl basis looks like this:

xpl$basis

Spreadsheet files

First, we write the basis to a CSV file and print that file:

write_kbase(xpl$basis, csvname)
cat(readLines(csvname), sep='\n')

Next, we write it to an ODS file and show a screenshot of that file opened in LibreOffice.

write_kbase(xpl$basis, odsname)
odsname

{width=400}
Figure 3: LibreOffice Screenshot with saved ODS format basis file

In the next step, we read the ODS file.

read_kbase(paste0(tempdir(), "/xpl_bas.ods"))

ASCII file

Finally, we write a classical ASCII file in SRBT format and print the file contents.

write_kbase(xpl$basis, srbtname, format="SRBT")
cat(readLines(srbtname), sep='\n')


Try the kstIO package in your browser

Any scripts or data that you put into this service are public.

kstIO documentation built on Sept. 7, 2026, 9:06 a.m.