R語言讀入數據庫的中英名詞互譯測試並計分腳本(考試用)

    1. 分子生物學中英文.csv,輸入文件,兩列,以tab鍵分隔的txt文本,沒有列名函數

    2. 錯誤的名解.csv, 若是在測試中拼寫錯誤,會寫出到這個文件,可用這個容易犯錯的名詞進行新的測試測試

    3. 注意加載data.table包,由於R語言readline函數,使用腳本不能很好交互,暫時只能在R交互模式下(終端輸入R)運行spa

    4. 這裏使用write寫出文件或者標準輸出,readline讀入鍵盤輸入,value進行得分統計code

 

library(data.table)


dt <- fread("分子生物學中英文.csv", sep = "\t", header =F) 
fileConn<-file("錯誤的名解.csv", "w")  

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)
相關文章
相關標籤/搜索