Hi, I'm trying to create questions using R/exams https://www.r-exams.org/ which can include outputs from R and jamovi.
The jamovi plots look fine but any formatted outputs with lines, such as t tests or ANOVA, attract the error:
! LaTeX Error: Unicode character ─ (U+2500)
not set up for use with LaTeX.
The code is for box lines in the output.
Does anyone know a workaround?
Thanks, Peter
R/exams
Re: R/exams
hi,
try escaping the code with stringi::stri_escape_unicode
cheers
try escaping the code with stringi::stri_escape_unicode
cheers
Re: R/exams
Thanks for the suggestion, but doesn't seem to work, using e.g.:
n <- 9 + sample(1:6, 4)
dat <- data.frame(Evaluation = rnorm(sum(n),
mean = rep(sample(seq(from = sample(25:55, 1), by = 1, length.out = sample(15:20, 1)), 4)/10, n),
sd = rep(sample(70:80, 4)/100, n)),
Treatment = factor(rep(1:4, n),
labels = c("Placebo", "Drug 1", "Drug 2", "Drug 3")))
a=jmv::anovaOneW(
formula = Evaluation ~ Treatment,
data = dat,
welchs = FALSE,
fishers = TRUE)
stri_unescape_unicode(a)
gives:
Error in as.vector(x, "character") :
cannot coerce type 'environment' to vector of type 'character'
n <- 9 + sample(1:6, 4)
dat <- data.frame(Evaluation = rnorm(sum(n),
mean = rep(sample(seq(from = sample(25:55, 1), by = 1, length.out = sample(15:20, 1)), 4)/10, n),
sd = rep(sample(70:80, 4)/100, n)),
Treatment = factor(rep(1:4, n),
labels = c("Placebo", "Drug 1", "Drug 2", "Drug 3")))
a=jmv::anovaOneW(
formula = Evaluation ~ Treatment,
data = dat,
welchs = FALSE,
fishers = TRUE)
stri_unescape_unicode(a)
gives:
Error in as.vector(x, "character") :
cannot coerce type 'environment' to vector of type 'character'
Re: R/exams
try this:
results <- jmv::contTables(ToothGrowth, formula=~dose:supp)
astext <- paste(capture.output(results), collapse="\n")
escaped <- stringi::stri_escape_unicode(astext)
cat(escaped)
jonathon
results <- jmv::contTables(ToothGrowth, formula=~dose:supp)
astext <- paste(capture.output(results), collapse="\n")
escaped <- stringi::stri_escape_unicode(astext)
cat(escaped)
jonathon
Re: R/exams
Couldn't get that to work, it gives error:
Error in readLines(con, encoding = "UTF-8", warn = FALSE) :
'con' is not a connection
No worries, I will use alternative formatted output like from the stargazer package
Thanks
Peter
Error in readLines(con, encoding = "UTF-8", warn = FALSE) :
'con' is not a connection
No worries, I will use alternative formatted output like from the stargazer package
Thanks
Peter
Re: R/exams
Mistakenly posted the wrong error.
This is what I get with the code Jonathon suggests (except using anovaOneW):
! Undefined control sequence.
l.17 \n
ONE-WAY ANOVA\n\n One-Way ANOVA (Fisher\'s) ...
Error: LaTeX failed to compile test1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test1.log for more info.
This is what I get with the code Jonathon suggests (except using anovaOneW):
! Undefined control sequence.
l.17 \n
ONE-WAY ANOVA\n\n One-Way ANOVA (Fisher\'s) ...
Error: LaTeX failed to compile test1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test1.log for more info.
Re: R/exams
so there's some collision between what's coming from R, and latex' control sequence.
to give a bit more of an overview of what's going on, often when we go from one format to another (i.e. text output to latex) there's something in one, that may have a special meaning in the other, and so we have to "escape" it.
an example might be greater than and less than signs in html ... in html these characters have a special meaning.
i.e. html looks like this:
<html>
<body>
<p>hello</p>
</body>
</html>
but of course if we want to put a less than sign, in the hello tex:
<p>a < b</p>
html gets all confused, because that's what it uses for it's format. we have to use a special escape sequence, like this:
<p>a < b</p>
essentially, you need to solve the same problem. what character in the output is latex mistaking for a control sequence? then escape that in the way that latex expects.
my best guess was that escaping everything non-ascii with it's \uXXXX code would fix the problem, but apparently not. i personally avoid latex like the plague so i'm not that familiar with it. but hopefully there's enough clues here to figure it out.
it's also possible someone with more familiarity with latex will chime in.
cheers
to give a bit more of an overview of what's going on, often when we go from one format to another (i.e. text output to latex) there's something in one, that may have a special meaning in the other, and so we have to "escape" it.
an example might be greater than and less than signs in html ... in html these characters have a special meaning.
i.e. html looks like this:
<html>
<body>
<p>hello</p>
</body>
</html>
but of course if we want to put a less than sign, in the hello tex:
<p>a < b</p>
html gets all confused, because that's what it uses for it's format. we have to use a special escape sequence, like this:
<p>a < b</p>
essentially, you need to solve the same problem. what character in the output is latex mistaking for a control sequence? then escape that in the way that latex expects.
my best guess was that escaping everything non-ascii with it's \uXXXX code would fix the problem, but apparently not. i personally avoid latex like the plague so i'm not that familiar with it. but hopefully there's enough clues here to figure it out.
it's also possible someone with more familiarity with latex will chime in.
cheers
Re: R/exams
Thanks Jonathon, that's helpful, will work on it
Peter
Peter