read_data_csv: Reads a data matrix from a CSV file

View source: R/reading_data.R

read_data_csvR Documentation

Reads a data matrix from a CSV file

Description

Imports a numeric data table from a CSV file and converts it to the internal matrix structure used by the package.

Usage

read_data_csv(
  filename,
  format = "row",
  header.col = TRUE,
  header.row = TRUE,
  sep = ","
)

Arguments

filename

Path to the CSV file containing the data matrix.

format

Data layout format, either "row" or "col". If "row", samples are assumed to be stored in rows and the matrix is transposed so that samples become columns in the returned matrix. If "col", the matrix is kept as read.

header.col

Logical; whether the file has a header row.

header.row

Logical; whether the file has a row names column.

sep

Field separator used in the file.

Value

A numeric matrix containing the imported data in the package's internal orientation, with variables in rows and samples in columns. If format = "row", the input table is transposed before being returned. The function stops with an error if non-numeric values are found in the data table.

Examples

data_file <- tempfile(fileext = ".csv")
data_in <- data.frame(
  x1 = c(1.1, 2.2, 3.3),
  x2 = c(4.4, 5.5, 6.6),
  row.names = c("s1", "s2", "s3")
)
utils::write.csv(data_in, data_file)
read_data_csv(data_file, format = "row", header.row = TRUE)


specmine documentation built on Aug. 5, 2026, 5:06 p.m.