Rmarkdown Error: Paragraph ended before \text# was complete. Unable to find source - r

When trying to knit an rmarkdown file to a PDF, I am encountering the following error. It is referencing a line number with no text reference and the line number is out of range of the number of lines of the file.
Rmarkdown Error:
! Paragraph ended before \text# was complete.
<to be read again>
\par
l.375
If anyone has encountered a similar error or has an idea about how to identify the location of the error in the file it'd be appreciated.

I have encountered this a couple times. It can be frustrating because you are likely finishing a lot of work and just creating the report so it can take some time to knit to find what is causing it.
The first thing you likely want to do is to heed that next line that has:
... See <your_output_file>.log for more info. ...
However because of the confluence of using all of TeX, Markdown and R's text generator, the line numbers are off a bit in this log file, so you may need to just start hunting.
I tend to use $\color{blue}{\text{, however likely searching for \text{ throughout your .Rmd file should be enough.
Likely you will need to escape some character as described in this answer. For me it is often parentheses.
For example I just got this error on a line that had:
$\color{blue}{\text{..., (if provided)...}}$
I was able to resolve with:
$\color{blue}{\text{..., \(if provided\)...}}$

Related

R Markdown Error reading bibliography: pandoc document conversion failed with error 25

pandoc seems to have a problem with reading my bib file giving me this error:
Error reading bibliography file library.bib:
(line 19001, column 1):
unexpected "#"
expecting space, ",", white space or "}"
Error: pandoc document conversion failed with error 25
Execution halted
I am using Mendeley to produce my library.bib and the file includes all of my references (almost 30 thousand lines).
When I search the line in question, everything seems to be in order (no unusual characters). Deleting the reference doesn't help. The "#" from the error is at the beginning of every reference in the file.
Using a smaller subset of my reference list from another folder doesn't help, I only managed to knit my document with a very small subset (1000 lines).
The library.bib is a copy in my project folder so it is not influenced by running Mendeley.
I can make a subfolder with references needed for this only document but it doesn't provide a long-term solution - I would like to use the whole library and not make a subfolder for each document I am working on.
Is there something simple I am missing?
Thanks!

Problems with .Rnw files and chunks in R

I am new to R and I made a rnw-file in R-Studio to create a PDF file for MikTex. The file consists of Latex-Code as well as R-Code in chunks and it has worked well before. Yesterday, I updated some packages and R-Studio and now I am getting a generell error. Even after searching for a longer time online, I couldn´t find a solution. For example, my first line starts with \documentclass{article} and I get the error "unexpected input in "\". Even when I open a totally new R-Sweave file (.Rnw) starting with \documentclass{article} it gives me the same error with the unexpected input.
The same, when I insert a chunk with R-Code starting with <<>>=, then it brings the same error "unexpected input in "<<" ".
Has anybody an idea, what could be the reason for that?

pandoc: Error producing PDF with R Markdown

When doing pandoc mymarkdown.md -o mypdf.pdf I get the following error:
! Undefined control sequence.
l.279 ...e know that the element stored at \(x \lt
pandoc: Error producing PDF
I'm confused, as using pandoc with any other markdown file works for me. l.279 ...e know that the element stored at \(x \lt corresponds to a line in my md file. If I remove that line from the file, the error persists, giving a different line and so on.
Unicode character fi (U+FB01)
It suggests there's a character that is cannot be converted correctly. If you're getting literally that error—with no visible character—then what's probably happening is that you have some sort of invisible or space Unicode character in your document. For instance, option+space on Mac will leave an invisible non-breaking space, which gives an error that looks like that.
What you can do is starting from an empty document, then add one paragraph at a time, until you find the problem, then try to "re-write" the problem part.

How to debug a Rsweave

I have an rsweave file that I run almost twice a week. Last time I used it a change a couple of things and when I run it to compile to pdf I got the following errors:
The pdf compiles complitly, and the only thing I notice that the error did is that the the pdf output has a extra page (the first one) all blank. I don't know how to make a reproducible example of the errors because I don't know whats the cause of it. But any way I just want to know generally how to debug a rsweave file when getting latex error like the ones in the picture
You don't say how you are running Sweave, but that looks like RStudio. To debug something like this, just run Sweave explicitly in the R console, e.g. if your input file is source.Rnw, run
Sweave('source.Rnw')
This will produce source.tex. Open that file in a text editor and look at the start of it. You will see that \Schunk is used on line 27, but \begin{document} doesn't occur until sometime later.
My guess is that you added some text or a code chunk to the header. All text belongs after \begin{document}.
Edited to add: It turns out from the comments below that you were using print(...) in a code chunk before \begin{document}. In Sweave, print output goes into the document. If you want a message to show up in the console log but not the document, use message("some text"). You'll also need to suppress the echoing of the command if you want to do this in the document header. For example,
<<echo=FALSE,results=hide>>=
message("Started at ", Sys.time())
#
will result in something like this in your console log:
1 : keep.source term hide (Untitled.Rnw:6)
Started at 2017-09-27 08:28:33
and nothing in the document.

Track the exact place of a not encoded character in an R script file

more a tip question that can save lots of time in many cases. I have a script.R file which I try to save and get the error:
Not all of the characters in ~/folder/script.R could be encoded using ASCII. To save using a different encoding, choose "File | Save with Encoding..." from the main menu.
I was working on this file for months and today I was editing like crazy my code and got this error for the first time, so obviously I inserted a character that can not be encoded while I was working today.
My question is, can I track and find this specific character and where exactly in the document is?
There are about 1000 lines in my code and it's almost impossible to manually search it.
Use tools::showNonASCIIfile() to spot the non-ascii.
Let me suggest two slight improvements this.
Process:
Save your file using a different encoding (eg UTF-8)
set a variable 'f' to the name of that file. something like this f <- yourpath\\yourfile.R
Then use tools::showNonASCIIfile(f) to display the faulty characters.
Something to check:
I have a Markdown file which I run to output to Word document (not important).
Some of the packages I used to initialise overload previous functions. I have found that the warning messages sometimes have nonASCII characters and this seems to have caused this message for me - some fault put all that output at the end of the file and I had to delete it anyway!
Check where characters are coming back from Warnings!
Cheers
Expanding the accepted answer with this answer to another question, to check for offending characters in the script currently open in RStudio, you can use this:
tools::showNonASCIIfile(rstudioapi::getSourceEditorContext()$path)

Resources