Last active
August 29, 2015 14:26
-
-
Save gatoravi/19fcdbbc4a703bbaac0a to your computer and use it in GitHub Desktop.
Test reading and writing to the same file in R
This file contains hidden or 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
#! /usr/bin/Rscript | |
test_read_write <- function() { | |
iris_copy <- read.table("iris_copy.tsv", head = T, sep = "\t") | |
iris_copy$Sepal.Length <- iris$Sepal.Length + 1 | |
write.table(iris_copy, "iris_copy.tsv", row.names = F, quote = F, | |
sep = "\t") | |
} | |
create_original_modified_iris <- function() { | |
data(iris) | |
write.table(iris_copy, "iris_original.tsv", row.names = F, quote = F, | |
sep = "\t") | |
iris_copy$Sepal.Length <- iris$Sepal.Length + 1 | |
write.table(iris_copy, "iris_modified.tsv", row.names = F, quote = F, | |
sep = "\t") | |
} | |
test_read_write() |
This file contains hidden or 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
#! /usr/bin/bash | |
#Make a copy of the iris dataset. | |
cp iris_original.tsv iris_copy.tsv | |
for i in `seq 1 10000`; | |
do | |
echo $i | |
#Read from file and write with minor mods | |
Rscript test_read_write.R | |
#Check if files are equal | |
if cmp -s iris_copy.tsv iris_modified.tsv; then | |
echo 'equal' | |
else | |
echo 'not equal' | |
exit 1 | |
fi | |
#Reset to original state | |
cp iris_original.tsv iris_copy.tsv | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment