1. 分子生物学中英文.csv,输入文件,两列,以tab键分隔的txt文本,没有列名
2. 错误的名解.csv, 如果在测试中拼写错误,会写出到这个文件,可用这个容易犯错的名词进行新的测试
3. 注意加载data.table包,因为r语言readline函数,使用脚本不能很好交互,暂时只能在r交互模式下(终端输入r)运行
4. 这里使用write写出文件或者标准输出,readline读入键盘输入,value进行得分统计
library(data.table) dt <- fread("分子生物学中英文.csv", sep = "\t", header =f) fileconn<-file("错误的名解.csv") value = 0 for(i in 1:nrow(dt)){ write(paste0(i," question"), stdout()) write(dt[i,v1], stdout()) input <- readline() if(length(input) == 0){ print("input can not be nothing") next() } if(input != dt[i,v2]){ write(dt[i,v2], stdout()) writelines(paste(dt[i,v1], dt[i,v2], sep = "\t"), fileconn) input <- readline() write("next!", stdout()) }else{ value = value 1 } } print(paste0("score ",value)) close(fileconn)
原文链接:http://www.cnblogs.com/ywliao/p/10498212.html