R/uploaddata.R

Defines functions uploaddata uploadtree

uploaddata <- function(csvfile, ...){
  if(substring(tolower(csvfile), nchar(csvfile)-3) != ".csv"){
    stop('Uploaded data needs to be .csv file. When using MS Excel, try "Save As" and select type "CSV (comma delimited)"');
  }

  #read csv data
  mydata <- read.csv(csvfile, row.names = NULL, stringsAsFactors=FALSE, ...);

  #convert columns with 7 or less levels to factors
  for(i in seq_along(mydata)){
    if(length(unique(mydata[[i]])) < 8){
      mydata[[i]] <- as.factor(mydata[[i]]);
    }
  }

  #return dataset
  return(mydata)
}

uploadtree <- function(phylofile, ...){
  if(substring(tolower(phylofile), nchar(phylofile)-3) != ".phy"){
    stop('Uploaded data needs to be newick file with extension *.phy.');
  }

  #read tree data
  mytree <- read.tree(phylofile, ...);


  #return dataset
  return(mytree)
}
lukejharmon/treePlotter documentation built on Nov. 4, 2019, 5:13 p.m.