R/corRead.R

Defines functions corRead

Documented in corRead

corRead <-
function(from=NULL, var_names=NULL, ...) {

  cat("\n")

  if (!is.null(from))
    if (nchar(from) == 0) from <- NULL  #  "" to NULL

  if (is.null(from)) {
    from <- file.choose()
    .dash(64)
    cat("File: \n")
    cat("   ", from, "\n")
    .dash(64)
    cat("\n")
  }

  myc <- as.matrix(read.table(from, ...))

  if (!is.numeric(myc))
    stop("Correlation matrix must be numeric. The values read include ",
         "non-numeric data. Check that the file contains only coefficients, ",
         "with no variable names or row labels.", call.=FALSE)

  if (nrow(myc) != ncol(myc))
    stop("Correlation matrix must be square; read matrix is ",
         nrow(myc), " x ", ncol(myc), ".", call.=FALSE)

  if (!is.null(var_names)) {
    if (length(var_names) != ncol(myc))
      stop("var_names length (", length(var_names), ") must equal ",
           "number of variables (", ncol(myc), ").", call.=FALSE)
    colnames(myc) <- var_names
  } else
    colnames(myc) <- to("X", ncol(myc), same_size=FALSE)
  rownames(myc) <- colnames(myc)

  return(myc)

}

Try the lessR package in your browser

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

lessR documentation built on June 21, 2026, 5:06 p.m.