Read the phenotype table used by shared dnaEPICO workflows, validate the sample identifier column, optionally subset the first nSamples, and return the targets as a base data.frame.

readPhenotypeTargets(
  phenoFile,
  sepType = "",
  nSamples = NA,
  SampleID = "Sample_Name",
  verbose = FALSE,
  logs = FALSE,
  log_dir = NULL,
  log_file = "log_readPhenotypeTargets.txt"
)

Arguments

phenoFile

Character. Path to the phenotype table on disk.

sepType

Character. Field separator used in phenoFile. Use "" (default) for a standard comma-separated file, "\\t" for a tab-delimited file, or another single-character separator accepted by utils::read.csv().

nSamples

Integer or NA. Number of rows to keep from the start of the phenotype table. The default NA reads and returns all rows.

SampleID

Character. Name of the column containing sample identifiers that will later be used to name methylation-array samples.

verbose

Logical. If TRUE, emit progress and preview messages with message(). The default is FALSE, so the function is quiet unless the user explicitly requests messages.

logs

Logical. If TRUE, write the same progress messages to a log file. The default is FALSE.

log_dir

Character or NULL. Directory where the log file should be written when logs = TRUE. If NULL, the current working directory is used.

log_file

Character. File name used when logs = TRUE. The default is "log_readPhenotypeTargets.txt".

Value

A data.frame containing the phenotype targets.

Examples

tmp <- tempdir()
pheno <- data.frame(
  Sample_Name = c("S1", "S2"),
  Sex = c("F", "M"),
  stringsAsFactors = FALSE
)
pheno_file <- file.path(tmp, "pheno.csv")
utils::write.csv(pheno, pheno_file, row.names = FALSE)
targets <- readPhenotypeTargets(
  phenoFile = pheno_file,
  SampleID = "Sample_Name"
)
stopifnot(is.data.frame(targets))
stopifnot(nrow(targets) == 2L)