SCM

Forum: support

Monitor Forum | Start New Thread Start New Thread
RE: Attach csv file to pdf/html exam [ Reply ]
By: Achim Zeileis on 2017-02-20 15:40
[forum:43890]
Great! If you end up writing your own exams2xyz() convenience interfaces, you might have to extend the list of functions recognized as using LaTeX/PDF (in addition to exams2pdf and exams2nops).

RE: Attach csv file to pdf/html exam [ Reply ]
By: Marcos Marvá on 2017-02-20 14:17
[forum:43888]
Thank you very much, Achim, this function works perfectly and makes things easier for us!

RE: Attach csv file to pdf/html exam [ Reply ]
By: Achim Zeileis on 2017-02-16 22:38
[forum:43886]
One way to go about the switch between

\textattachfile{myfile.csv}{\tt myfile}

in exams2pdf() and

\url{myfile.csv}

in exams2html() etc. would be the following. In your set of tools include the following function:

attachfile <- function(file, latex = NULL) {
if(is.null(latex)) latex <- match_exams_call() %in% c("exams2pdf", "exams2nops")
file <- if(latex) {
sprintf("\\\\textattachfile{%s}{\\\\tt %s}", file, file)
} else {
sprintf("\\\\url{%s}", file)
}
return(file)
}

And then in the question text you can just say

\Sexpr{attachfile("myfile.csv")}

When called within exams2pdf() this will create the attachfile code and otherwise a plain url. Note that this requires the devel version of the "exams" package here from R-Forge and R 3.2.0.

RE: Attach csv file to pdf/html exam [ Reply ]
By: Achim Zeileis on 2017-02-13 15:54
[forum:43862]
All work with exams() is discouraged ;-) More seriously: For backward compatibility it's still useful to have it included but exams2pdf() is much more flexible.

As for attaching data to both PDF and HTML files. I'll keep this in mind and maybe we can think of a workaround. However, so far I have advertised PDF only for the situation where I want to print the exams/exercises - and then I cannot attach files anyways. And if I want to share exercises electronically, HTML or a learning management system are usually better solutions.

Having said that: If you want to implement a switch in the exercise, you can of course do so by setting some global option. Another (somewhat experimental) solution would be to make the distinction based on match_exams_call(). Note, though, that this requires the most recent devel version of "exams" and at least R 3.2.0.

RE: Attach csv file to pdf/html exam [ Reply ]
By: Marcos Marvá on 2017-02-13 09:59
[forum:43859]
Achim; many thanks for your answer.

The example code worked fine (apart from the Warning message: In FUN(X[[i]], ...): incomplete final line found on 'plain-attachfile.tex'). I think my problem was that I was using the old exams() function instead of exams2pdf().

As for our ExamineR repo project, we would like to write questions that produce outputs with attached csv files in pdf/html in an unified way. Attaching such a files is important not only from a very applied point of view (if students can not read data, they can not do statistics) but also to create realistic questions, as well as to prepare, for instance, questions on ANOVA.

A possible solution consists of set an if-else that enables \url or \textattachfile depending on a parameter value set in the exams-generator-file.

I didn't know about the exams2blackboard() function (great!).

RE: Attach csv file to pdf/html exam [ Reply ]
By: Achim Zeileis on 2017-02-08 14:35
[forum:43852]

plain-attachfile.tex (13) downloads
Because R-Forge appears to have trouble with .zip attachments, I'm including the second attachment in this separate reply...sorry for the inconvenience.

RE: Attach csv file to pdf/html exam [ Reply ]
By: Achim Zeileis on 2017-02-08 14:33
[forum:43851]

lm-attachfile.Rnw (14) downloads
Marco, I understand. I've now taken a look at the "attachfile" package which I didn't know before and illustrate below how it can be combined with exams2pdf(). Unofrtunately, I cannot comment on your regression.zip file because R-Forge has somehow messed up the binary attachment and I couldn't open it. (I hope my attachments work ok.) So here we go:

(a) To employ extended LaTeX tools, you typically have to do two things: set up the .tex template suitably and then use exercise files that employ these features. This gives you a full flexibility and control over the PDF output. The only disadvantage is that the HTML converters (tth/ttm or pandoc) will typically not be able to correctly process these extended features.

(b) In this particular case I have set up a "plain-attachfile.tex" template that I just copied from "plain.tex" and inserted:

\usepackage{attachfile}
\attachfilesetup{color=0.5 0 0}

And then I modified the "lm.Rnw" exercise to "lm-attachfile.Rnw" by using

\textattachfile{regression.csv}{\tt regression.csv}

instead of \url{regression.csv}. Then running

exams2pdf("lm-attachfile.Rnw", template = "plain-attachfile.tex")

should give the output you are looking for. So this is fine for the PDF output _but_ running exams2html() on the same file swallows the attachment. One would have to tweak something along the transformation process to fix this but I'm not sure whether a really convenient solution exists. I had hoped that "pandoc" supports this out of the box but didn't find anything.

(c) Note that the most recent "exams" release also has a function exams2blackboard() which generates XML that can be imported to Blackboard.

RE: Attach csv file to pdf/html exam [ Reply ]
By: Marcos Marvá on 2017-02-08 13:14
[forum:43850]

regression.zip (21) downloads
Hi Achim;
many thanks for your hints and your comment on our repo. Indeed, my question was somehow related to it.

i) Using the argument base64 = TRUE in the exams2html() function solves our problem, and it is good news.

ii) On the other hand, we would like to write questions such that the output file embeds the csv file with raw data (in the way you have shown us with exams2html(c("lm", "boxhist"), base64 = TRUE)) but regardless it is in html or pdf format. In this way the data and its question(s) will remain together. We have done it using Rmd files that are independent of the exams package (see attached file)

We would like to enrich the Examiner project with questions based on raw data so that we could produce questionnaires in whatever format (html, pdf,...). Anyway, we deploy the questionnaires via a plain web page (since our institution provides us with Blackboard instead of Moodle or any other suitable platform) so that the base64= TRUE solution helps us. But produce also such a pdf files may be an interesting feature.

RE: Attach csv file to pdf/html exam [ Reply ]
By: Achim Zeileis on 2017-02-05 20:25
[forum:43845]
Marcos, thanks for your interest. We're glad the package is useful for you!

And yes, it is easy to produce individual CSV files for each random variation of the exercise template. See the following for two examples contained in the manuscript:

exams2html(c("lm", "boxhist"))

By default the supplementary CSV files are stored in a temporary directory on the machine where exams2html() is executed. But using

exams2html(c("lm", "boxhist"), base64 = TRUE)

the CSV files can also be directly embedded into the HTML file using Base64 encoding.

The question is how you want to deploy the exercises+data to your students. Typically, I would use a learning management system like Moodle for this - and exams2moodle() leverages Moodle's plugin for such supplementary files.

If you just want to put up the exercises plus supplementary files on a plain web page, then you could take the Base64 route. Or you post-process the output of exams2html() (or exams2pdf()) and wrap everything into some ZIP file or so.

If you provide some more information on the desired context I might be able to give some more recommendations.

P.S.: I also looked at your ExamineR project on GitHub (https://github.com/PostDataStatistics/ExamineR) which seems to be a nice and useful effort! If you have further questions, don't hesitate to use this forum!

Attach csv file to pdf/html exam [ Reply ]
By: Marcos Marvá on 2017-02-05 16:29
[forum:43843]
Hi;
thanks for this useful package.

We would like to prepare exams/quizzes based on raw data. Thus, we would like to attach a csv file to the pdf/html exam that contains the data to be analyzed. We have tried to use \usepackage{attachfile} almost everywhere...but we have failed...Is it possible to do so? does anybody know how to proceed?



Thanks to:
Vienna University of Economics and Business Powered By FusionForge