Last active
April 8, 2017 01:32
-
-
Save kevincdurand1/970fc14a8bdf01e035e06370c7edfdfc to your computer and use it in GitHub Desktop.
Writing text and output from analyses to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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