sample.interaction <- function(read.r2=TRUE, type="p", pch=16) {
r1 <- Readline(prompt="first input: ")
r2 <- if (read.r2) Readline(prompt="second input: ", info="2nd input")
else "-- no input -- "
cat("Mark some points with the right mouse key, then leave with the left mouse key
")
do.call(getOption("device"), list())
plot(Inf, Inf, xlim=c(-1,1), ylim=c(-1,1), xlab="", ylab="")
l <- Locator(100, info="locator input", type=type, pch=pch)
r3 <- Readline(prompt="third input: ", info="last input")
return(list(r1=r1, r2=r2, l=l, r3=r3))
}
#########################
## user terminal input ##
#########################
{
useraction("start.register")
str(sample.interaction())
str(l <- getactionlist())
}
#################
## just replay ##
#################useraction("replay", sleep=2, wait=interactive() * 0.2 * 5,
PrintLevel=2, actionlist=l)
str(sample.interaction(type="l"))
##############################################
## modify first the input list, then replay ##
##############################################
l2 <- l[-2]
l2[[1]] <- list("some other words", info="changed input")
str(l2)
useraction("replay", sleep=1, wait=interactive() * 0.05,
PrintLevel=0, l2)
str(sample.interaction(read.r2=FALSE, type="o")) # input now from l2
Readline(prompt="new input: ", info="?!") # switch to terminal
## since end of stored list
# str(getactionlist()) # new input has not been not stored ...
####################################################
## use of the two lists, l and l2, in a mixed way ##
####################################################
useraction("replay", sleep=2, wait=interactive() * 0.05,
PrintLevel=0, actionlist=l)
Readline(prompt="first input of 1: ")
dump <- getactions()
useraction("replay", sleep=0.5, wait=interactive() * 0.05,
PrintLevel=0, actionlist=l2)
Readline(prompt="first input of 2: ")
dump2 <- putactions(dump)
Readline(prompt="second input of 1: ")
## locator call reading from list 1:
plot(Inf, Inf, xlim=c(-1,1), ylim=c(-1,1), xlab="", ylab="")
Locator(100, info="locator input", type="p")
dump <- putactions(dump2)
##locator call reading from list 2:
Locator(100, info="locator input", type="p", pch=20, col="blue")
Readline(prompt="last input of 2: ")
putactions(dump)
Readline(prompt="last input of 1: ")
#####################################################
## see help("eval.parameters") for another example ##
#####################################################
Run the code above in your browser using DataCamp Workspace