library(grid)
library(dplyr)
library(ggplot2)
library(gridExtra)
library(datasets)

#set the working directory
setwd("C:/Users~/Data")

#save data in d
d <- "C:/Users~/Data/"name".csv"

name <- tools::file_path_sans_ext(basename(d)) #Extracts file name with |basename|, and |file_path...| remove extension

#read d and store data in ds
ds <- read.table(d, header = TRUE, sep = ",", stringsAsFactors = FALSE)

# One Way Anova (Completely Randomized Design)
fit <- aov(ds$REC ~ ds$Assay, data=ds) #Change headers for the ones used

plot(fit) # diagnostic plots

summary(fit) # display Type I ANOVA table
drop1(fit,~.,test="F") # type III SS and F Tests 

# Tukey Honestly Significant Differences
TukeyHSD(fit) # where fit comes from aov() 

options(max.print=999999)

results <- list(name, summary(fit), drop1(fit,~.,test="F"), TukeyHSD(fit))

capture.output(results, file = sprintf("%s.doc", name), append = TRUE) #Gets file input name and add to output .doc file.

