read_factor: Read in a factor writtin in the CLS format

View source: R/read_cls.R

read_factorR Documentation

Read in a factor writtin in the CLS format

Description

Read in a factor writtin in the CLS format

Usage

read_factor(con = stdin(), offset = 0)

read_cls(con = stdin(), offset = 0)

Arguments

con

File or connection to read file from

offset

The integer representing the first level, default is set to 0, for some software it can be set to 1

Value

A factor with levels as defined in the CLS file.

Note

The original CLS format specifies that both tab or space can be used as separators. This makes it unable to represent factors with sapces in levels. In order to accomodate CLS format for these factors, we propose using tab as separators in CLS files when encoding factors in R. The default setting of read_factor and write_factor uses tab. Though read_factor can handle both separators, as long as in the file a separator is consistenly used.

See Also

write_factor

Examples

set.seed(1887)
tempfac <- factor(sample(LETTERS, 30, replace=TRUE), levels=sample(LETTERS))
tempfile <- tempfile()
write_factor(tempfac, tempfile)
stopifnot(identical(tempfac, read_factor(tempfile)))

write_factor(tempfac, tempfile, sep=" ")
stopifnot(identical(tempfac, read_factor(tempfile)))

idir <- system.file("extdata", package="ribiosIO")
sample.cls <- read_factor(file.path(idir, "test.cls"))
expFac <- factor(c("Case", "Control")[c(1,0,1,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0)+1],
levels=c("Case", "Control"))
stopifnot(identical(sample.cls, expFac))


ribiosIO documentation built on Feb. 20, 2026, 5:09 p.m.