write_factor: Write a factor in the CLS format

View source: R/read_cls.R

write_factorR Documentation

Write a factor in the CLS format

Description

Write a factor in the CLS format

Usage

write_factor(fac, con = stdout(), offset = 0, sep = c("\t", " "))

write_cls(fac, con = stdout(), offset = 0, sep = c("\t", " "))

Arguments

fac

A factor

con

Connection to write to

offset

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

sep

Separator used in the CLS format, can be '\t' (recommended) or ' ' (not to be used when space exists in levels)

Value

No return value, called for side effects (writes to connection).

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.

See Also

read_factor

Examples

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

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