Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevincdurand1/970fc14a8bdf01e035e06370c7edfdfc to your computer and use it in GitHub Desktop.
Save kevincdurand1/970fc14a8bdf01e035e06370c7edfdfc to your computer and use it in GitHub Desktop.
Writing text and output from analyses to a file
# Start writing to an output file
sink('analysis-output.txt')
set.seed(12345)
x <-rnorm(10,10,1)
y <-rnorm(10,11,1)
# Do some stuff here
cat(sprintf("x has %d elements:\n", length(x)))
print(x)
cat("y =", y, "\n")
cat("=============================\n")
cat("T-test between x and y\n")
cat("=============================\n")
t.test(x,y)
# Stop writing to the file
sink()
# Append to the file
sink('analysis-output.txt', append=TRUE)
cat("Some more stuff here...\n")
sink()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment