SCM

Forum: support

Monitor Forum | Start New Thread Start New Thread
RE: Exercises must be below working directory? [ Reply ]
By: Achim Zeileis on 2025-12-19 12:12
[forum:50137]
Sigbert, thanks for the example. Yes, indeed, the supplementary data file is the issue. The default in include_supplement() is to search the exercise directory recursively.

The exercise directory can be set via the "edir" argument. The default is the current working directory. Thus, when you do:

exams2html("../exercise/laspeyres_herrderringe.Rmd")

the "working/" directory is the exercise directory and supplements are searched there and in its subdirectories.

The simple workaround is to use:

exams2html("laspeyres_herrderringe.Rmd", edir = "../exercise/")

which uses "../exercise/" as the exercise directory and successfully finds the supplement.

For searching all exercises in edir you can use:

edir <- "../exercise/"
files <- list.files(edir, pattern = "\\.Rmd$", recursive = TRUE)
exams2html(files, edir = edir)

P.S.: In this particular case I would probably store the base prices within the exercise and not within an Excel file. For example in a named vector (rather than a data.frame):

pq <- c(
"Elbenbrot (Lembas)" = 5,
"Heilkräuter (Athelas)" = 10,
"Wasservorräte" = 2,
"Met (Honigwein)" = 7,
"Schafswolle" = 4,
"Holz (Bau-/Brennholz)" = 3,
"Fisch (Anduin)" = 6,
"Gerste" = 1,
"Äpfel" = 2,
"Wein (Gondor)" = 8,
"Schmiedeeisen" = 15,
"Pfeil und Bogen" = 12,
"Fackeln und Öl" = 3,
"Kerzen" = 2,
"Salz" = 1,
"Getrocknetes Fleisch" = 9,
"Seile und Lederwaren" = 5,
"Fackelholz" = 3,
"Räucherwerk / Kräuterrauch" = 4,
"Pergament und Tinte" = 7
)

RE: Exercises must be below working directory? [ Reply ]
By: Sigbert Klinke on 2025-12-19 07:36
[forum:50136]

exams.zip (3) downloads
Hi,

I provided a M(N)WE in the zip file, see test.R . Maybe it is problem of the supplement data file?

Best Sigbert

RE: Exercises must be below working dirictory? [ Reply ]
By: Achim Zeileis on 2025-12-18 17:01
[forum:50135]
I cannot replicate this problem on my Linux machine when using relative paths with "..". (On Linux "..." does not seem to work.) See my replication code below which runs smoothly.

So maybe it's the three "..." rather than two ".."? Or a Windows thing?

As an alternative you could try working with file names without paths and setting the edir= argument.

files_only <- basename(list.files(path = path, pattern = "\\.Rmd$", recursive = TRUE))
exams2html(files, edir = path)

----------

Replication code for your example:

## create temporary directory (tdir)
## with sub-directories for exercises (edir) and working (wdir)
tdir <- tempfile()
dir.create(tdir)
setwd(tdir)
dir.create("edir")
dir.create("wdir")

## copy two exercises to edir
file.copy(system.file("exercises", c("swisscapital.Rmd", "switzerland.Rmd"), package = "exams"), "edir/")

## run code in wdir
setwd("wdir")
path <- ".."
files <- list.files(path = path, pattern = "\\.Rmd$", recursive = TRUE, full.names = TRUE)
exams2html(files)

Exercises must be below working dirictory? [ Reply ]
By: Sigbert Klinke on 2025-12-18 09:40
[forum:50134]
Hi,

I am trying the following:

library("exams")
path <- "..."
# setwd(path)
files <- list.files(path = path, pattern = "\\.Rmd$", recursive = TRUE, full.names = TRUE)
exams2html(files, verbose = TRUE)

The exercise files are referenced using (absolute) paths, but they are not located in or below the current working directory. In this case, exams2html()/exams2pdf() stop processing at the first exercise.

If I uncomment setwd(path), so that the exercises are located in or below the working directory, everything runs correctly.

Should these functions not work without explicitly setting the working directory?

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