Search code examples
rrstudior-exams

The command exams2html() does not generate HTML page when it is run from RStudio?


I do not know why exams2html() does not produce HTML page when I run the command from RStudio but it is fine when I run from R itself. Both R and RStudio are updated to the latest version. I saw Zeileis et al. (2014) mentioned a similar issue in their paper "Flexible Generation of E-Learning Exams in R...". But it is unclear for me why this happens with the latest version? Does anyone have any idea how to fix that issue? Thank you!


Solution

  • A colleague of mine reported a similar behavior recently under Windows 10 using R 4.0.0 and a current RStudio. We could track this down to browseURL() not working in the default temporary directory associated with an R session. Maybe you have the same problem.

    For him the following worked:

    library("exams")
    exams2html("swisscapital.Rmd", dir = ".")
    browseURL("plain1.html")
    

    This creates the plain1.html output HTML file in the current working directory (".") and then manually opens the file in the browser using browseURL().

    By default (without a dir= argument), exams2html() essentially does the same thing in a dedicated temporary subdirectory in tempdir(). On my colleagues machine, essentially all steps worked but `browseURL() couldn't open the HTML file that was successfully created.

    If this is also what happens for you, you can try the following:

    exams2html("swisscapital.Rmd")
    

    which should create at least one copy of plain1.html in a subdirectory of tempdir():

    dir(tempdir(), recursive = TRUE)
    

    If so, you can try to open that file from within R

    browseURL(dir(tempdir(), "plain1.html", recursive = TRUE, full = TRUE)[1])
    

    or manually. For my colleague, manually opening the file (e.g., via the Windows Explorer) worked but browseURL() did not.

    Unfortunately, this is as much as I know about the problem up to now... It's possible that this is related to the RStudio browser but we haven't explored this further.

    As for the problem described in Zeileis et al. (2014): This was fixed a long time ago by RStudio. Nevertheless you could try to see what happens if you set: options(browser = NULL) before running exams2html().

    Any other pointers are also welcome.