How markdown cant identify the output - r-markdown

I ma trying to run following code and it keeping running into an error. I did work on previous occasion, but now it doesn't seem to work.
---
output:
word_document:
reference_docx: format.docx
---
Error: object 'output' not found

Related

tbl_summary Error message in UseMethod("ungroup")

I have a tbl_summary which outputs great when run in a script, however I am writing a report in rmarkdown and every time I knit to pdf I get an error message:
Error in UseMethod("ungroup")
(see image below)
Why is this happening? All the variables are continuous except for 'Region' which is what I'm grouping by. Again it outputs fine until I go to knit the file.

rmarkdown when I print table in a loop adds "Loading [MathJax]/extensions/MathZoom.js" to my pdf

I am trying to make a pdf with tables using a loop in rmarkdown.
But I get this "Loading [MathJax]/extensions/MathZoom.js" added to the bottom of the pdf.
How do I get rid of this message?
Here is my rmd code
title: "Some tables"
output: html_document
for(i in 1:2){
mytable = kbl(head(mtcars))
cat( print(mytable))
}
I make the pdf by typing the following in the console (typically I run this from another R program).
library(kableExtra)
rmarkdown::render("tables_in_loop.rmd")
pagedown::chrome_print("tables_in_loop.html")
How do I get rid of the loading message?
When I just use
kbl(head(mtcars))
I don't get the message but I want to print out lots of tables with a loop.
I know Rmd can do pdfs, but I get an error about running pdflatex.exe from
C:\AppData\Roaming\TinyTeX\bin\win32
I don't have administrative rights to execute this. If you have suggestions about this they are much appreciated.
Also I have a 64 bit windows 10 computer and I'm running R in 64.
Thank you so much,
Jennifer
I figured it out, I need to just use cat(mytable) not cat(print(mytable))

Bookdown : Automatic figure numbering and cross-referencing doesn't work

I am trying to write my master's thesis in RMarkdown.
I first tried to fix an issue with the position of my figures in the pdf document, and used this method : https://stackoverflow.com/a/33801326.
So my YAML header looked like this :
title: "example"
author: "me"
output:
rmarkdown::pdf_document:
fig_caption: yes
includes:
in_header: preamble-latex.tex
Then, I wanted my figures numbered and easily cross-referenced. I tried changing the output to bookdown::pdf_document2: since the method I was taught (that is ![caption\label{mylabel}] and \autoref{mylabel} ) did not work at all and ended up with this :
---
title: "example"
author: "me"
output:
bookdown::pdf_document2:
fig_caption: yes
includes:
in_header: preamble-latex.tex
---
```{r label, echo=FALSE, fig.cap="caption", out.width='75%', out.height='75%'}
knitr::include_graphics("../../images/my_image.png")
\```
and tried to cross-reference like this : #ref(fig:label)
The image does appear in the right place, at the right size and with my caption. But it is not numbered (there is no "Figure 1" mention before my caption) and the reference appears almost exactly as is in the knitted document, only without the backslash (so #ref(fig:label)). No matter where I look or what I do, I cannot seem to change that...
Could it be that bookdown's automatic numbering does not work because of the changes I made in the YAML header to keep my images in the right place? What can I do to fix this issue?
Problem has been solved by
giving up on using bookdown and coming back to the recommended output (that is ::rmarkdown:pdf_document: )
updating all R and tinytex packages
adding a line in the LaTex file :
/usepackage{float}
to fix an newly appeared error (unknown float option h)
The figures were then held in the right spot and numbered (although they weren't numbered before...)
using \autoref{fig:label} instead of \#ref(fig:label) for the cross-reference, in conjunction with include_graphics()

RMarkdown to PPT: not loading reference_doc()

I am trying to use a PPT template to format a RStudio > RMarkdown > PPT file. Here's my testing file (saved as testing.Rmd):
---
title: "Aarduous Aardvarks"
author: "Aanonymous Aardvark"
date: "5/4/2019"
output: powerpoint_presentation
reference_doc: template.pptx
---
## My title
```{r myplot}
plot(mtcars)
```
When I first knit this, a PPT file was generated. I opened that file, made the Slide Master background red and the font blue (deliberately hideous for testing), saved it as "template.pptx" in the same folder as above.
However, when I re-knit the document, the background is still white and the font is still black. What do I need to get my template file recognized?
System:
Windows 7 Professional
Rstudio 1.2.1335
Rmarkdown 1.12
Pandoc: 2.6
PPT 2010 v14.0.6129.5000
Indentation in YAML is important. Use the structure as described in the official docs:
---
title: "Aarduous Aardvarks"
output:
powerpoint_presentation:
reference_doc: template.pptx
---
I have had this same problem, but it does not repair when the YAML above is inserted. The additional changes helped me solve the problem:
Save the reference_doc as a .potx file format, and refer to that extension in the YAML header
Go into View -> Slide Master to make sure the slides in the master are the format you expect (one time I thought I made the changes, but they showed up on the Home menu and not the Slide Master)
Under the Home menu, click the Dropdown under Layout and make sure AT THE LEAST that you see these four elements:
Title
Section Header
Title and Content
Two Content
When all three of these are taken care of, my slides knit fine from the Rmd.
I was facing a similar error when knitting to a powerpoint template- the indentation as documented (indenting 'reference_doc:...') was giving me an error: "Scanner error: mapping values are not allowed in this context", which suggested that the indentation was wrong in the YAML. I was able to resolve (through trial and error) with the following formatting:
---
title: "TITLE"
author: "Mike Harris"
date: "4/9/2021"
resource_files:
- template.pptx
output:
powerpoint_presentation:
reference_doc: template.pptx
---
Hopefully this saves someone a little extra time.

Use additional Latex packages for math expressions in RMarkdown `output = "html_document"`

I`m aware how to use additional Latex-packages for pdf-format output from .Rmd files using
---
header-includes:
- \usepackage{mathtools}
---
in the YAML header.
However, this does (of course) not work if one specifies output: html_document.
---
output: html_document
header-includes:
- \usepackage{mathtools}
---
Using additional Latex-Packages could be of interest for output: html_document, too - especially in math expressions (MWE below)
---
title: "MWE"
output: html_document
header-includes:
- \usepackage{mathtools}
---
## Use "Defined by" Symbol
$$sin(x) \coloneqq \frac{opposite}{hypothenuse}$$
MathJax offer a number of extensions, and there are third-party extensions as well. If your desired package is not available in this way, then things get difficult.
Simple commands, such as \coloneqq, can be recreated using \newcommand. The simplest way is to add these via the include-before option. Using your MWE with a solution from Mathematics Meta SE, one gets:
---
title: "MWE"
output:
html_document: default
include-before:
- '$\newcommand{\coloneqq}{\mathrel{=}}$'
---
## Use "Defined by" Symbol
$$sin(x) \coloneqq \frac{opposite}{hypothenuse}$$
Output:
Background
RMarkdown is build around pandoc, which performs most of the format conversions. Pandoc creates PDF via LaTeX (by default), and will simply include any raw LaTeX commands which are given in the source. When seeing \usepackage{mathtools}, the package is not parsed, but the command is simply added verbatim to the intermediate LaTeX. However, when exporting to HTML, it wouldn't make sense to pass through LaTeX commands, so any such command will simply be omitted from the output, so any \usepackage in your document won't effect the HTML output.
Alternative solution
If you are using very complex LaTeX-packages, then you could consider setting up a complex pipeline to still use it: E.g, one could use a pandoc filter to extract all equations, compile each equation as a separate document, and then convert the resulting PDF to SVG. Finally, that SVG can then be included in the HTML output. This is non-trivial and probably not worth the effort. A similar approach is recommended to include TikZ pictures.