mardi 2 septembre 2014

Getting R to give me a prompt mid-script


Vote count:

0




I've got a situation where I'm comparing data files that have measurements of the same phenomenon (they are actually XML surveys from ODK of the same respondent). The first represents the original survey and the second represents a resurvey.


I want to compare the two files, and then decide which to delete. To save time mousing around, I'd like to build a simple script that involves a prompt asking me which of the two I'd like to delete, much in the way I need to hit return when I set devAskNewPage(TRUE)


Here is a dummy script, missing the code for the prompt that I'd like to have happen:



write.csv(data.frame(x = 0:100,y = 0:100+rnorm(101,sd=5)),file="csv1.csv")
write.csv(data.frame(x = 0:100,y = rnorm(101,sd=5)),file="csv2.csv")

csv1 = read.csv("csv1.csv")
csv2 = read.csv("csv2.csv")

plot(1:10,cex=0,xlim=c(0,100),ylim = c(-10,110))
with(csv1,points(x,y,col="red"))
with(csv2,points(x,y,col="blue"))

whattodo = NA
print("What would you like to do? Type 1 to delete the first one, type 2 to delete the second one, type 3 to delete neither.")

Here, some sort of code that makes my system wait for a prompt, which would set the whattodo variable

if (whattodo == 1) {system('rm csv1')}
if (whattodo == 2) {system('rm csv2')}


asked 7 secs ago

ACD

558






Getting R to give me a prompt mid-script

Aucun commentaire:

Enregistrer un commentaire