Cant knit rmarkdown document

Hello everyone,

As the title says, I've been trying to knit a .Rmd document, but I havent been able to. When I hit the knit button, this error comes up

output file: Prueba45.knit.md

! Text line contains an invalid character.
l.170 ## 5
% of the random confidence intervals do not contain Var = 144.

Error: Failed to compile Prueba45.tex. See The R package tinytex - Helper Functions to Manage TinyTeX, and Compile LaTeX Documents - Yihui Xie | 谢益辉 for debugging tips. See Prueba45.log for more info.
Execution halted

I have done everything I could: Reinstall R, Rstudio, MikTex, installes tinytex package.... but no luck.

Aparrently the issue is with the function cisim included in the PASWR2 package. This image shows the graph that cisim generates, which is the one that gives problems

Any ideas? Thanks in advance

Could you add a little example dataset and code for just the part of the .Rmd document that is causing the problem. If you haven't ever made a reproducible example (i.e., reprex) before, you can get some ideas here:

Based on questions and answers I saw here and here that I found from searching the error message, I'm guessing this is somehow related to latex.

The problematic part is just a line of code, and i dont really understand how to do a reprex (Im basically new to R), but hopefully this image helps.

I think you're actually close to a reprex. :slightly_smiling_face: You should provide the code in your question instead of a screenshot so someone who wants to help can copy and paste directly into R.

Since you are asking a question about a RMD, you should also include information in the YAML header so we can see what kind of document your are making.

We also have a FAQ on making a reprex for R beginners, because it can feel really difficult when you're just getting started: FAQ: How to do a minimal reproducible example ( reprex ) for beginners

2 Likes

It looks like the problem has to do with the message that prints as R output from cisim(), not the plot. (If you knit to a HTML you can see that the message prints oddly, which made me wonder if this was the problem).

This is apparently output, though, and not a message per se, so message = FALSE in the chunk header didn't help.

This message can be suppressed by suppressing the output with results = "hide". You still get the plot, though. This allowed me to knit to a PDF without error.

```{r, results = "hide"}
library(PASWR2)
cisim(samples = 100, n = 125, parameter = 758, sigma = 12, conf.level = .95, type = "Var")
```
1 Like

It actually worked!! Thank you very much!! But may I ask why does your solution work, why does result = "hide" make the problem dissapear?

I was seeing the same error messages about the Unicode character, so I knew that somewhere there was a character that wasn't being recognized.

I thought the problem involved the plot text because I didn't really notice the text output, but when I knit the same thing to an HTML document the text output that cisim() prints had weird symbols in it.

7 % of the random confidence intervals do not contain Var = 1 .

Since those weird symbols showed in the text output, I thought I'd see what happened if I suppressed the text output. The results chunk option is relevant to text output. You can see important info on Chunk Options here.

results : ( 'markup' ; character) takes these possible values

  • markup : mark up the results using the output hook, e.g. put results in a special LaTeX environment
  • asis : output as-is, i.e., write raw results from R into the output document
  • hold : hold all the output pieces and push them to the end of a chunk
  • hide (or FALSE ): hide results; this option only applies to normal R output (not warnings, messages or errors)

Hiding the text output means the weird symbols aren't printed and, voila, no latex error. I'm guessing there is a way to get latex to print that symbol if we knew what it was but since the same text output is actually on the plot this is a relatively simple way to fix the problem.

You could consider reporting this to the package maintainers (I didn't check if they have an issue tracker) in case they want to look into it further so this doesn't happen to others.

Don't forget to mark you question solved answered (if it has been):

It has been answered, and I also know why it didnt work. Thank you very much!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.