Skip to content

Commit

Permalink
V0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusmmp committed Mar 25, 2021
1 parent 94a4362 commit c698ea8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 35 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: exams2sakai
Title: Automatic Generation of Exams in R for 'Sakai'
Version: 0.1
Version: 0.2
Authors@R: c(
person(given = "Fuensanta",
family = "Arnaldos García",
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# exams2sakai 0.2

* Adding tolerance for Numeric Response Questions.

* Set converter = "pandoc-mathjax" by default option.

* Fixing bug 'owd not found' when zip=FALSE.

# exams2sakai 0.1

* First CRAN release version.
Expand Down
70 changes: 41 additions & 29 deletions R/exams2sakai.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ exams2sakai <- function(file, n = 1L, nsamp = NULL, dir = ".",
sdescription = "Please answer the following question.",
maxattempts = 1, cutvalue = 0, solutionswitch = TRUE, zip = TRUE,
points = NULL, eval = list(partial = TRUE, negative = FALSE),
converter = NULL, xmlcollapse = FALSE, ...)
converter = "pandoc-mathjax", xmlcollapse = FALSE, ...)
{
## default converter is "ttm" if all exercises are Rnw, otherwise "pandoc"
if(is.null(converter)) {
converter <- if(any(tolower(tools::file_ext(unlist(file))) == "rmd")) "pandoc" else "ttm"
}
## set up .html transformer
htmltransform <- make_exercise_transform_html(converter = converter, ...)

Expand Down Expand Up @@ -337,12 +333,11 @@ exams2sakai <- function(file, n = 1L, nsamp = NULL, dir = ".",
on.exit(setwd(owd), add = TRUE)
setwd(test_dir)
utils::zip(zipfile = zipname <- paste(name, "zip", sep = "."), files = list.files(test_dir))
if(dir == ".") {
dir = owd
}
} else zipname <- list.files(test_dir)

if(dir == ".") {
dir = owd
}

## copy the final .zip file
file.copy(file.path(test_dir, zipname), dir, recursive = TRUE)

Expand Down Expand Up @@ -606,29 +601,46 @@ make_itembody_sakai <- function(rtiming = FALSE, shuffle = FALSE, rshuffle = shu
if(fix_num) {
correct_num[[i]] <- c(correct_num[[i]],
paste('<varequal respident="', ids[[i]]$response,
'" case="No"><![CDATA[', if(!is.null(digits)) {
format(round(solution[[i]][j], digits), nsmall = digits)
} else solution[[i]][j],
'" case="No"><![CDATA[', solution[[i]][j] - max(tol[[i]]), '|',
solution[[i]][j] + max(tol[[i]]),
']]></varequal>', sep = "")
)
}
wrong_num[[i]] <- paste(
paste(c('\n<or>', paste('<varequal respident="', ids[[i]]$response,
'" case="No"><![CDATA[', if(!is.null(digits)) {
format(round(solution[[i]][j], digits), nsmall = digits)
} else solution[[i]][j],
']]></varequal>\n', sep = "")), collapse = '\n', sep = ''),
'<and>\n',
paste('<vargte respident="', ids[[i]]$response, '"><![CDATA[',
solution[[i]][j] - max(tol[[i]]),
']]></vargte>\n', sep = ""),
paste('<varlte respident="', ids[[i]]$response, '"><![CDATA[',
solution[[i]][j] + max(tol[[i]]),
']]></varlte>\n', sep = ""),
'</and>',
'\n</or>',
collapse = '\n', sep = ''
)
if (tol[[i]] == 0) {
wrong_num[[i]] <- paste(
paste(c('\n<or>', paste('<varequal respident="', ids[[i]]$response,
'" case="No"><![CDATA[', solution[[i]][j] ,
']]></varequal>\n', sep = "")), collapse = '\n', sep = ''),
'<and>\n',
paste('<vargte respident="', ids[[i]]$response, '"><![CDATA[',
solution[[i]][j],
']]></vargte>\n', sep = ""),
paste('<varlte respident="', ids[[i]]$response, '"><![CDATA[',
solution[[i]][j],
']]></varlte>\n', sep = ""),
'</and>',
'\n</or>',
collapse = '\n', sep = ''
)
}
else {
wrong_num[[i]] <- paste(
paste(c('\n<or>', paste('<varequal respident="', ids[[i]]$response,
'" case="No"><![CDATA[', solution[[i]][j] - max(tol[[i]]), '|',
solution[[i]][j] + max(tol[[i]]),
']]></varequal>\n', sep = "")), collapse = '\n', sep = ''),
'<and>\n',
paste('<vargte respident="', ids[[i]]$response, '"><![CDATA[',
solution[[i]][j] - max(tol[[i]]),
']]></vargte>\n', sep = ""),
paste('<varlte respident="', ids[[i]]$response, '"><![CDATA[',
solution[[i]][j] + max(tol[[i]]),
']]></varlte>\n', sep = ""),
'</and>',
'\n</or>',
collapse = '\n', sep = ''
)
}
}
)
}
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ library( exams2sakai )

myexam <- list( "boxplots", "regression", "scatterplot", "relfreq" )

ex1 <- exams2sakai( myexam, n = 1, converter="pandoc-mathjax",
ex1 <- exams2sakai( myexam, n = 1,
verbose = TRUE,
dir = ".", points = c( 1 ) )

Expand Down Expand Up @@ -74,6 +74,7 @@ extype: mchoice
extype: num # Only working with one solution
exsingle: TRUE # mcss
exsingle: FALSE # mca
extol: 0.1 # Tolerance for Numeric Response questions
exsolution: 0100001
exshuffle: 5
exextra[randomize]: TRUE # Randomize answers
Expand Down
7 changes: 3 additions & 4 deletions man/exams2sakai.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
maxattempts = 1, cutvalue = 0, solutionswitch = TRUE,
zip = TRUE, points = NULL,
eval = list(partial = TRUE, negative = FALSE),
converter = NULL, xmlcollapse = FALSE, \dots)
converter = "pandoc-mathjax", xmlcollapse = FALSE, \dots)

make_itembody_sakai(rtiming = FALSE, shuffle = FALSE,
rshuffle = shuffle, minnumber = NULL, maxnumber = NULL,
Expand Down Expand Up @@ -111,8 +111,7 @@
correct solutions for numeric exercises/answers as well as to obtain results when archiving tests.
Note that this is a workaround, which works e.g. within OLAT.}
\item{converter}{character. Argument passed on to \code{make_exercise_transform_html}.
The default for \code{converter} is set to \code{"ttm"} unless there are Rmd
exercises in \code{file} where \code{"pandoc"} is used.}
The default for \code{converter} is set to \code{"pandoc-mathjax"}}
\item{xmlcollapse}{logical or character. Should line breaks be collapsed in the XML
code. If \code{TRUE} everything is collapsed with spaces (\code{" "}) but other collapse
characters could be supplied.}
Expand Down Expand Up @@ -231,7 +230,7 @@ myexam <- list( "boxplots", "regression", "scatterplot", "relfreq" )
dir.create(mydir <- tempfile())

## generate Sakai quiz in temporary directory
exams2sakai( myexam, n = 1, converter="pandoc-mathjax",
exams2sakai( myexam, n = 1,
verbose = TRUE,
dir = "mydir", points = c( 1 ) )

Expand Down

0 comments on commit c698ea8

Please sign in to comment.