Edit
Thanks to some SO (i.e., #tmpname12345) users, I've come to the conclusion that my problem (described below) is likely caused by the differences between v0.2.64 and v0.3.11 of rmarkdown. The question now becomes:
Is there a way I can prevent rmarkdown version 0.3.11 and knitr from adding a line after the title of a .pdf file?
Original Question
I've come across a curious difference between compiling a .pdf document with the same yaml header block on two different computers with Rstudio and knitr. The difference is that on one computer, an additional line is inserted after the title while on the other, the line is not inserted (the preferred behavior). I would like to prevent the line from being inserted regardless of where the document is compiled.
I am using 32-bit R 3.1.2 on both computers. The yaml block is identical between both computers.
Here is the .Rmd file:
---
title: Header Test
output: pdf_document
---
My#gmail.com\hfill \hfill Address
Phone number\hfill \hfill Town, State, ZIP
Evidence of no additional line after the title, generated from my laptop with rmarkdown version 0.2.64:
Evidence of the additional line after the title, generated from my desktop with rmarkdown version 0.3.11:
Initially, I thought it may have been a function of the knitr package version, so I upgraded the package in the second image from 1.7 to the newest available version on CRAN, 1.9, but the extra line still remains.
I have also considered that this is an artifact of the Rstudio version on my laptop but if it is, I don't want to upgrade as the first image is the preferred.
I routinely edit .Rmd files in my Google Drive folder from both a desktop computer and my laptop, accessing the same file. Unfortunately, they compile differently. I prefer that there is no line added after the title. At this point, I don't want to change anything on my laptop, fearing that compilation will start to include the extra line.
Is there some way I can force knitr to not add the additional line?
One way is to create your own latex template that formats the header like you want. You can use the default template as a starting point here. Then save the file as .tex in the same directory as your Rmd file and add this to the yaml header:
output:
pdf_document:
template: mytemplate.tex
Related
I have an R markdown file which I'd like to be available on my corporate Shiny Server.
According to R Markdown: The Definitive Guide I can add runtime: shiny to the YAML metadata at the top of the Rmd file to turn it into a Shiny document. I have done this and it works. If I click "Run Document" in RStudio it will run the Rmd and I will see the report with no problems.
My project is located in the ShinyApps directory where the Shiny Server is looking for apps to serve. When I hit the URL for this project I get the report without any charts. I just get broken image icons where the charts should be. (I am using RStudio Server so it is the exact same files being accessed by RStudio and Shiny Server).
R version 3.4.3, Shiny Server version 1.5.6.875
UPDATE: I have reproduced the behaviour with the simplest possible example. I created a new RStudio project - just a plain project - called TEST located in my ShinyApps directory. Then I created a new R Markdown file, which I called TEST.Rmd. This file is pre-populated with example RMarkdown using the cars and pressure built-in datasets. I changed the YAML header to include runtime: shiny. The RStudio "knit" button is replaced by the "Run Document" button, as expected, and clicking this runs the document and works as expected. Attempting to view the page via the Shiny Server has the same issue whereby the plot is not included; a broken image icon takes its place.
UPDATE 2: As requested, here is the Markdown file. It is literally the sample file generated by RStudio with the addition of runtime: shiny in the YAML header.
---
title: "Test RMarkdown"
author: "Michael Henry"
date: "4/6/2020"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
UPDATE 3: So I went hunting around the server looking for a log file for Shiny Server. I do not have any administrator privileges so I've never looked for this before, but I found a log file which included this: /lib64/libpango-1.0.so.0: undefined symbol: g_log_structured_standard. It turns out there is a bug in RHEL which has a fix available so I have put a request in with my administrator to apply the fix. I will report back after this has been applied as to whether it resolved my issue.
UPDATE 4: It turns out my RHEL server is up-to-date; it already has the version of glib2 suggested by the bugfix. The fact that I am still getting this error is therefore something that my administrator is going to escalate to Red Hat.
UPDATE 5: The Red Hat support suggested there was another glib2 so file lying around and it turned out that this was the case. Removing this file resolved the issue!
So, I think you might need to add some extra code to make the markdown application run as you expect in the Shiny Server environment
try wrapping the charts and plots with the following:
renderPlot({})
This gives the server an order to both run the plot and then make it available to the Shiny document. Shiny is a weird thing to straight up R programmers.
You are basically computing and creating things in an R environment and handing them off to a Javascript/HTML one which needs to know in its own language what to do. That renderPlot({}) tells the JS component how to promote the R output to your page.
You can see from this section of the reference document you linked to what the format is and how it is promoted to the page by Shiny.
If you are still stuck after doing this, reach back out and I will try to help trouble shoot!
Searching for the error message: /lib64/libpango-1.0.so.0: undefined symbol: g_log_structured_standard led to a known issue with RHEL whereby there was an older version of glib2 on the system that did not contain the symbol g_log_structured_standard. In my case the server was up-to-date and had the correct version of glib2, but there was another version of this library lying around which was causing the issue.
The moral of the story: search for the log files early and follow the leads contained therein!
I'm writing a paper using R Markdown and TinyTex, using Biblatex for referencing. It works fine with default referencing styles, but I need to add a custom bibliography and citation style for the journal I'm writing for.
I need to follow the Unified Stylesheet for Linguistics, for which there is a Biblatex implementation available on Github here, containing a .bbx and .cbx file.
I've tried adding those .bbx and .cbx files to my local copy of TinyTex, inside Library/TinyTex/texmf-local/tex/latex/biblatex. My YAML header includes:
output:
pdf_document:
citation_package: biblatex
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
When I knit the document, I get the following error:
tlmgr search --file --global '/biblatex-dm.cfg'
! Package keyval Error: bibstyle undefined.
I don't have a biblatex-dm.cfg file (nor do I really understand what that would be). I would have thought the .bbx and .cbx files would be sufficient, based on the regular installation instructions in the style's Github repo.
Where should I put .bbx and .cbx files, so that tlmgr can find them? And/or what additional steps do I need to take to use this style with my paper?
====================================================================
UPDATE: The problem seems to be coming from the Pandoc LaTeX template that R Markdown uses.
Setting aside R Markdown, I created a smaller minimal LaTeX example:
main.tex
references.bib
Where main.tex is:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}
\addbibresource{references.bib}
\begin{document}
Something something \citep{darwin_origin_1859}.
\printbibliography
\end{document}
And references.bib is:
#book{darwin_origin_1859,
location = {London},
title = {On the Origin of Species by Means of Natural Selection},
publisher = {J. Murray},
author = {Darwin, Charles},
date = {1859}
}
I had success compiling this example using the sequence of commands pdflatex, biber, pdflatex, pdflatex. Thus it seems my local TeX installation knows about the biblatex-sp-unified.bbx and sp-authoryear-comp.cbx files I added and can use them just fine.
Subsequently, I created an equivalent minimal R Markdown document with the YAML header:
title: "Untitled"
output:
pdf_document:
citation_package: biblatex
bibliography: references.bib
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
and body:
Something something [#darwin_origin_1859].
This time, I got the same old error message from before:
tlmgr search --file --global '/biblatex-dm.cfg'
! Package keyval Error: bibstyle undefined.
This would seem to suggest that the problem is caused by something in Pandoc's LaTeX template, but I don't know what.
Just to confirm that it's definitely the Pandoc template and not my own installation/setup, I took the .tex file that gets produced when I knit the minimal R Markdown example above, and tried to compile it in Overleaf (with biblatex-sp-unified.bbx and sp-authoryear-comp.cbx files added). I reproduced the same error.
Although I think I've localised the problem, I'd still very much like to understand what and where the problem is in the Pandoc template. I'd also be keen to hear if anyone has any fixes (other than just using a different template or writing my own).
UPDATE: This seems to be an issue with using an out-of-date version of R Markdown and/or Pandoc.
I was using rmarkdown package v.1. At time of writing, the most up-to-date version is 2.1.
I updated all my packages and updated Rstudio (which currently ships with Pandoc v2.3.1) and no longer experience problems. I also upgraded R (from 3.5.something to 3.6.2) and did a fresh re-install of tinytex while I was at it, but I'm not sure whether those things had an effect for this particular problem.
Now, when I put biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp] in my YAML header, it's correctly converted into the LaTeX command \usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}, rather than the \ExecuteBibliographyOptions command as described below.
Ralf Stubner initially suggested I check my R Markdown/Pandoc versions in the comments. Please give his comments an upvote if you them useful as well.
Problem recap:
I'm writing a document in R Markdown and I have a particular referencing style that I'd like to use with biblatex. I have a .bbx and .cbx file defining the style, available on Github (linked above). The problem is that the document fails to compile, saying biblio/citation styles are undefined (even when the style files are in the project folder itself).
I've found that the problem was caused by the way I was passing options to biblatex. In my YAML Header, the line:
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
gets converted to the latex command:
\ExecuteBibliographyOptions{bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp}
I'm not sure why, but when this command is included, it produces the errors I was observing.
Installing new Biblatex style:
I'm finding that TeX doesn't know about the .bbx and .cbx files when they're in my ~/Library/TinyTex/texmf-local/tex/latex/biblatex directory (which is where I expected to put them based on the Github installation instructions).
To get the referencing style recognised by the system, I placed .bbx and .cbx files inside ~/Library/TinyTex/texmf-dist/tex/latex/biblatex/bbx and ~/Library/TinyTex/texmf-dist/tex/latex/biblatex/cbx respectively. Then, in the terminal, I ran sudo mktexlsr.
(Alternatively, for use only with a particular document, the .bbx and .cbx files could simply be kept in the project directory with the R Markdown file)
Original hacky answer (but see update above):
Instead of using biblatexoptions in the YAML header of the R Markdown document, I simply knitted it with citation_package: biblatex (and no extra options). I also added keep_tex: yes. Then, I opened the resulting tex file, found the \usepackage{bibtex} command and added the desired options, so it read \usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}.
Finally, I ran pdflatex and biber on the tex file in the terminal. Clearly far from ideal, but it will technically produce the desired output.
I'm writing a document in rmarkdown with the thesisdown template.
Related to the issue thesisdown-41: how can I add a new language for highlighting which is currently not supported?
The project mentioned in the link is derived from bookdown
Under the hood bookdown uses pandoc for tranforming markdown to HTML/PDF/.... From pandoc's manual at http://pandoc.org/MANUAL.html#syntax-highlighting we get:
The library used for highlighting is skylighting.
The list of available languages can be retrieved with pandoc --list-highlight-languages
Slightly off topic, but I just worked out how to do this in RMarkdown rather than Bookdown. I suspect you'll need this and maybe a little more.
Passing extra arguments to Pandoc via the YAML front-matter:
output:
html_document:
highlight: haddock
pandoc_args: ["--syntax-definition", "cobol.xml"]
Obtain the XML syntax definition file from somewhere (or create it). I got my COBOL one from:
wget http://kde.6490.n7.nabble.com/attachment/1163657/0/cobol.xml.gz
The syntax of the highliting file is as used by the Kate project in KDE.
Obtain the pre-req language.dtd file, this is some deep dependency with pandoc.
wget https://raw.githubusercontent.com/jgm/highlighting-kate/master/xml/language.dtd
If've just added the two files to my git repo, plus the YAML lines to my RMarkdown, and everything then worked on other developers machines.
I was trying to convert an .rmd document to .md to upload on GitHub using output: github_document in my YAML header.
Apparently, the conversion does not respect the two or more spaces I used in my .rmd file to force a linebreak.
Example: I created this little .rmd file:
---
title: "Line Break issue"
output: github_document
---
1. My First point
Another point right below
and more
1. My second point
I used two spaces to force a break between "My first Point" and "Another point..." and "and more". When I knit, the preview is fine, however, when I upload to GitHub the linebreaks are only adequately respected in the .rmd file as you can see here but apparently gone in the .md file as you can here.
Why is that?
EDIT:
I am using rmarkdown_0.9.6 within RStudio Version 0.99.1130 on R 3.3.0.
It looks to me as if the behavior of GitHub's markdown renderer has changed. Formerly GitHub Flavored Markdown automatically created an HTML line break for any line break within Markdown (even those without 2 trailing spaces). As a result the pandoc conversion to github_markdown stripped off the 2 trailing spaces (as they were not necessary or meaningful in github_markdown).
Posting some test files on GitHub today however it looks like they now require the two spaces to yield a line break. I don't know if this change is permanent or temporary (as it will be sure to break a bunch of existing code). To deal with this I've added a hard_line_breaks option to github_document:
https://github.com/rstudio/rmarkdown/commit/0cbfcf7ebde5f587e70a064ae7c484cfd849ba6a
With this change the YAML of your example would need to look like this to preserve the two-spaces:
---
title: "Line Break issue"
output:
github_document:
hard_line_breaks: false
---
If this appears to be a permanent change by GitHub then I'll change the default to true so github_document will produce the right markdown by default.
The new version of Rstudio (0.98.932) has many new options including knit to PDF. An article describing the new version has a comment from Dave that says:
...after installing rstudio 0.98.932 I don’t get the little dropdown menu
for knit-pdf or word when editing a .Rmd file.
I'm having the same issue. A helpful response was posted:
It might be that either:
a) You are not running R 3.0 (which is required for RMarkdown v2); or
b) You have a custom markdown renderer defined (markdownToHTML
option). You can check for this by executing:
getOption(“rstudio.markdownToHTML”)
That solved Dave's problem (b), but when I run that command I get NULL
> getOption("rstudio.markdownToHTML")
NULL
Which I assume means I don't have a custom markdown renderer defined. (Previously I did in a cusomized .Rprofile, but I removed that.) My R version is 3.1.0.
Am I misunderstanding the getOption command? Could something else be tripping up my Rstudio?
I have just installed the new version of RStudio (0.98.932), which prompted me to upgrade a couple of packages (I can't remember which, although I see I have knitr 1.6, markdown 0.7 and rmarkdown 0.2.46). At first I had the same problem; there was only a single 'knit' option on the tool bar. I managed to get the ability to knit to .pdf by adding the following to the head of my .Rmd file.
---
title: "Sample Document"
output: pdf_document
---
Having done that, I now find I do have a drop down menu with options to knit to HTML, PDF and word. There's also a little gear icon that provides access to the R Markdown document options that wasn't there before. I have no idea what the problem was but it seems OK now!
Adding on #nicholas response
This is also why I create new .Rmd documents through the RStudio gui
File > New File > R markdown.
This way the YAML header is populated correctly.