#' 从题库中创建试题选择考试题目并创立文件夹
#' @description 主要用这个命令,替代create_test_paper
#' @author Gabe Lee
#' @param testrowid
#' @return testmd
#' @export
#' @examples
#' # med_micro_test_2015_cn_benke_A <- as.character(c(1,5,8,17,24,27))
#' # make_dir_create_test(med_micro_test_2015_cn_benke_A)
#' med_micro_test_1602_grad_A <- as.character(c(4,5))
#' make_dir_create_test(med_micro_test_1602_grad_A)
#'
make_dir_create_test <- function(testName,testname=deparse(substitute(testName)))
{
prjPath = "/Users/gabe/liguomin.teaching/Testbanks/Tests/"
setwd(prjPath)
# make the exam directory
library(dplyr)
#testname <- deparse(substitute(testName))
diryear <- stringr::str_extract(testname,"[0-9]{4}")
dirtest <- stringr::str_replace(testname,"_[ABC]$","")
dataYear <- paste0(prjPath,diryear)
if (!file.exists(dataYear)) {
dir.create(file.path(dataYear))
}
dataDir <- paste0(prjPath,diryear,"/",dirtest)
if (!file.exists(dataDir)) {
dir.create(file.path(dataDir))
}
# copy the makefile to the md directory
cpmakefile <- paste0("cp makefile ", dataDir)
system(cpmakefile)
setwd(dataDir)
# create exams
my_db <- dplyr::src_sqlite(path="/Users/gabe/liguomin.teaching/Testbanks/testbankmd.sqlite")
# 取得变量名称
outname <- deparse(substitute(testName))
testbank_tb = dplyr::tbl(my_db,'testbank')
testbank_tb %>%
dplyr::filter(mdid %in% testName) %>%
dplyr::select(content) %>%
# To pull down all the results use collect()
collect %>%
as.list %>%
unlist %>%
paste(.,collapse = "\n") %>%
cat(., file=paste0(dataDir,"/",outname,".md"))
# add test year
# add_exam_year(testName)
# make doc and pdf files
system('make pdfdoc')
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.