diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b6a065 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.Rproj.user +.Rhistory +.RData +.Ruserdata diff --git a/exo.Moodle.template.R b/exo.Moodle.template.R new file mode 100644 index 0000000..04bff86 --- /dev/null +++ b/exo.Moodle.template.R @@ -0,0 +1,64 @@ +## load package +if(!require("knitr")) install.packages("knitr") +if(!require("tth")) install.packages("tth") +if(!require("base64enc")) install.packages("base64enc") +if(!require("exams")) install.packages("exams") +library("exams") + +# for data export +currentdir.wd <- getwd() +script.path <- paste0(currentdir.wd, "/source/R/") +data.path <- paste0(currentdir.wd, "/source/data/") +fig.path <- paste0(currentdir.wd, "/source/fig/") + +# set the seed +set.seed(2022) +# set the exercises +exo <- c("prefixe_template_specific.Rnw") + +# export as HTML for a quick check +exams2html( + file = exo, + encoding = "UTF-8", + edir = "./source", + template = "plain8", + n = 1 +) + +# export as pdf for a quick check +exams2pdf( + file = exo, + encoding = "UTF-8", + edir = "./source", + # template = "plain8", + name = "2022.Template", + dir = "output", + # comment it for a direct pdf viewer + n = 1 +) + +# generate Moodle exo XML file +exams2moodle( + file = exo, + name = "2022.Template", + encoding = "UTF-8", + converter = "ttm", #xml based langage for math eqn displaying (take care to do not use chrome for practising moodle exercices) + dir = "output", + cloze = list( + cloze_mchoice_display = "MULTIRESPONSE", + shuffle = TRUE, + eval = list( + partial = TRUE, + negative = FALSE, + rule = "true" + ) + ), + edir = "source", + rule = "none", + n = 1 +) + + +# Note: Due to the dot "." in the name of the file +# a warning is made during the compilation +# You can avoid this message by changing to a dash or an underscore \ No newline at end of file diff --git a/exo.Moodle.template.Rproj b/exo.Moodle.template.Rproj new file mode 100644 index 0000000..6636d95 --- /dev/null +++ b/exo.Moodle.template.Rproj @@ -0,0 +1,14 @@ +Version: 1.0 + +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: knitr +LaTeX: pdfLaTeX +DisableExecuteRprofile: Yes diff --git a/source/R/prefixe_template_specific.R b/source/R/prefixe_template_specific.R new file mode 100644 index 0000000..6bb2af5 --- /dev/null +++ b/source/R/prefixe_template_specific.R @@ -0,0 +1,30 @@ +# install package if needed +if(!require("dplyr")) install.packages("dplyr") +# package loading +library(dplyr) + +############################################### +# parameters # +############################################### +param.lambda <- 5 +param.size <- 10 + +############################################### +# data # +############################################### +x <- rpois(param.size, lambda = param.lambda) +df <- data.frame(x) + +dat <- matrix(c( + "A", "Lettre 1 de l'alphabet", + "B", "Lettre 2 de l'alphabet", + "C", "Lettre 3 de l'alphabet"), + nrow = 2 +) +selectedindex <- sample(1:ncol(dat), 1) + +localdata <- read.csv("givendata.csv") + +############################################### +# computation # +############################################### diff --git a/source/data/givendata.csv b/source/data/givendata.csv new file mode 100644 index 0000000..20c0a8b --- /dev/null +++ b/source/data/givendata.csv @@ -0,0 +1,5 @@ +"y" +1 +2 +3 + diff --git a/source/data/specific.csv b/source/data/specific.csv new file mode 100644 index 0000000..d036c18 --- /dev/null +++ b/source/data/specific.csv @@ -0,0 +1,11 @@ +"x" +7 +6 +2 +5 +3 +6 +2 +2 +4 +6 diff --git a/source/fig/by-sa.svg b/source/fig/by-sa.svg new file mode 100644 index 0000000..60b44e3 --- /dev/null +++ b/source/fig/by-sa.svg @@ -0,0 +1,74 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/source/fig/cc-by-sa.png b/source/fig/cc-by-sa.png new file mode 100644 index 0000000..afd9108 Binary files /dev/null and b/source/fig/cc-by-sa.png differ diff --git a/source/prefixe_template_specific.Rnw b/source/prefixe_template_specific.Rnw new file mode 100644 index 0000000..747568b --- /dev/null +++ b/source/prefixe_template_specific.Rnw @@ -0,0 +1,154 @@ +% ############################################### +% # parameters # +% ############################################### +<<>>= +prefixe <- "prefixe" +name <- "template" +specific <- "specific" +scriptname <- paste0(prefixe,"_", name, "_", specific, ".R") +currentfile <- paste0(scriptname, "nw") +dataset.name <- paste0(specific, ".csv") +# precision +nbdecimal <- 3 +precision <- 10^(-nbdecimal) +@ + +% ############################################### +% # files availability # +% ############################################### +<>= +# include_supplement(file = scriptname, recursive = TRUE) +# this file is copied in the current tempory folder +# and hence is available further +include_supplement(file = "cc-by-sa.png", recursive = TRUE) +include_supplement(file = "givendata.csv", recursive = TRUE) +@ + +% ############################################### +% # sourcing process # +% ############################################### +<>= +source(paste0(script.path, scriptname)) +@ + +% ############################################### +% # optional: libraries loading # +% ############################################### +<<>>= +# install package if needed +if(!require("ggplot2")) install.packages("ggplot2") +# package loading +library(ggplot2) +@ + +% ############################################### +% # Data # +% ############################################### +<>= +# initilialize a solution vector +question <- list() +reponse <- list() +sol <- c() +type <- c() +point <- c() + +question[[1]] <- paste("option",1:5) +solution <- mchoice2string(c(rep(F,4),T)) +sol <- c(sol, solution) +reponse[[1]] <- question[[1]][string2mchoice(solution)] +type <- c(type,"schoice") +point <- c(point, 1L) + +question[[2]] <- paste("option",1:5) +solution <- mchoice2string(c(T,F,T,F,T)) +sol <- c(sol, solution) +reponse[[2]] <- question[[2]][string2mchoice(solution)] +type <- c(type, "mchoice") +point <- c(point, sum(string2mchoice(solution))) + +question[[3]] <- "" +solution <- round(mean(x), nbdecimal) +sol <- c(sol, solution) +reponse[[3]] <- solution +type <- c(type, "num") +point <- c(point, 3L) + +question[[4]] <- dat[2, selectedindex] +solution <- dat[1, selectedindex] +sol <- c(sol, solution) +reponse[[4]] <- solution +type <- c(type, "string") +point <- c(point, 1L) + +tol <- ifelse(type == "num", precision, 0) + +# data export to a local folder +write.csv(df, file = paste0(data.path,dataset.name), row.names = FALSE) +# data export to temporary folder so that it is available in the question section +write.csv(df, file = dataset.name, row.names = FALSE) +@ + +% ############################################### +% # statement # +% ############################################### +\begin{question} +Texte de l'énoncé.\\ +Fichier de la question \url{\Sexpr{dataset.name}}.\\ +Utilisez une précision de \Sexpr{precision}. + + \begin{enumerate} + \item (\Sexpr{point[1]} pt) Première question : un choix simple. ##ANSWER1## + \item (\Sexpr{point[2]} pt) Deuxième question : un choix multiple. ##ANSWER2## + \item (\Sexpr{point[3]} pt) Troisième question : une valeur numérique. ##ANSWER3## + \item (\Sexpr{point[4]} pt) Quatrième question : une chaîne de caractères. ##ANSWER4## + \end{enumerate} + +<>= +answerlist(unlist(question)) +@ + +\end{question} + +% ############################################### +% # solution # +% ############################################### +\begin{solution} +Les réponses sont : +<<>>= +reponse +@ + +Graphique +<>= +ggplot(data=df, aes(x)) + + geom_bar() +@ + +Autre information +<<>>= +summary(x) +@ + +Données lues localement +<<>>= +localdata +@ + +{ +\vspace{5mm} +\tiny\it +\begin{tabular}{ll} +auteur & \href{https://people.hes-so.ch/fr/profile/211212093-sacha-varone}{Sacha Varone}, HES-SO\\ +licence & \includegraphics{cc-by-sa.png} +\end{tabular} +\end{solution} + +%% ---------- meta-data --------- % +%% \extype{cloze} +%% \exsolution{\Sexpr{paste(sol, collapse = "|")}} +%% \exclozetype{\Sexpr{paste(type, collapse = "|")}} +%% \exsection{\Sexpr{name}} +%% \exname{\Sexpr{name}} +%% \extol{\Sexpr{paste(tol, collapse = "|")}} +%% \expoints{\Sexpr{noquote(paste(point, collapse = "|"))}} +%% \exversion{v0}