在我的代码中,在运行时输入。如果输入数据的时间延迟也显示为我的运行时。如何从代码中删除用户交互时间?
示例代码。如果我调用fun(),readline在运行时获取值。“Answer”输入延迟的值也包含在运行时间中。何时删除用户从运行时间输入延迟?
fun <- function() {
start.time <- Sys.time()
i<-1
ANSWER <- readline("Are you a satisfied R user? ")
while(i<1000){
sink("D://newdatset.txt")
print(ANSWER)
sink()
i<-i+1}
unlink("D://newdatset.txt")
if (substr(ANSWER, 1, 1) == "n")
cat("This is impossible. YOU LIED!\n")
else
cat("I knew it.\n")
end.time <- Sys.time()
time.taken <-end.time - start.time
time.taken
}
如果我打电话给乐趣(y)。确认答案正确。
fun <- function(x) {
start.time <- Sys.time()
i<-1
ANSWER <- "x"
while(i<1000)
{
sink("D://NH.txt")
print(ANSWER)
sink()
i<-i+1}
if (substr(ANSWER, 1, 1) == "n")
cat("This is impossible. YOU LIED!\n")
else
cat("I knew it.\n")
end.time <- Sys.time()
time.taken <-end.time - start.time
print( time.taken)}