1

I have two YAML metadata blocks, and it appears that the 2nd metadata block is not being read. I think this has something to do with Pandoc, but I'm not sure. I used the same code several months ago, and it was working.

I do get the warning [WARNING] Could not parse YAML metadata at line 73 column 1: :2:41: Expected start of line which I've never gotten before. If I try to include the 2nd block in the first, nothing runs.

Does anyone have any ideas?

Thanks,

James

Here are the two metadata blocks:

---
fig: no crop
geometry: left=1mm, right=1mm, top=1mm, bottom=1mm, asymmetric
indent: TRUE
output:
  word_document:
    reference_docx: my-styles.docx 
  html_document:
    df_print: paged
    fig_caption: yes
    includes:
      in_header: my_header.tex
  pdf_document: default
header-includes: 
    - \usepackage{placeins}
    - \usepackage{indentfirst}
    - \usepackage{setspace}\doublespacing
    - \usepackage{lineno}
    - \linenumbers
---


---
title: Education and Crime Across America: Inequity's Cost

author: |
  | James Ades ^[Jades@UCSD.edu] $^1$, Jyoti Mishra $^2$, Project i-Lead $^3$
  | $^1$$^2$UCSD, $^3$Berkeley, Stanford, UCSF
  
bibliography: Ed.Crime.bib

abstract: | 
All of my abstract information...
---
James
  • 459
  • 2
  • 14
  • Any chance to show `YAML metadata at line 73`? – Panwen Wang Jul 15 '20 at 22:53
  • It's weird because line 73 is just r code, so I think it's referring to somewhere in the 2nd metadata block. Regardless, even if I take out everything so that there is just the title, in which case I don't receive the warning, it still doesn't print the title. – James Jul 15 '20 at 23:08

1 Answers1

3

The problem is the colon in your title. I have had this issue before (but didn't seen it on SO anywhere after a quick search, so I don't think this is a duplicate). You'll notice that for many of your entries in the YAML you have a colon followed by more specification. Anytime it sees a colon, it thinks that's what you're trying to do, so the title with a colon messes up the parsing.

You can fix with either

title: Education and Crime Across America: Inequity's Cost

since : is HTML for colon, or use quotes:

title: "Education and Crime Across America: Inequity's Cost"

For me, your code with both of those slight modifications knitted just fine on my machine (after deleting the lines about the bib and header include that refer to local files not on my machine).

Additional details

So, here's the full R Markdown file I used:

---
fig: no crop
geometry: left=1mm, right=1mm, top=1mm, bottom=1mm, asymmetric
indent: TRUE
output:
  html_document:
    df_print: paged
    fig_caption: yes
  word_document: default
  pdf_document: default
header-includes: 
    - \usepackage{placeins}
    - \usepackage{indentfirst}
    - \usepackage{setspace}\doublespacing
    - \usepackage{lineno}
    - \linenumbers
title: "Education and Crime Across America: Inequity's Cost"
---

---
author: |
  | James Ades ^[Jades@UCSD.edu] $^1$, Jyoti Mishra $^2$, Project i-Lead $^3$
  | $^1$$^2$UCSD, $^3$Berkeley, Stanford, UCSF

abstract: | 
    All of my abstract information...
---

xxx

And here is a screenshot of the output:

enter image description here

Here's the sessionInfo() in case there are differences in the software versions we're running:

R version 4.0.0 (2020-04-24)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] compiler_4.0.0   rsconnect_0.8.16 htmltools_0.5.0  tools_4.0.0     
 [5] yaml_2.2.1       rmarkdown_2.3    knitr_1.29       xfun_0.15       
 [9] digest_0.6.25    rlang_0.4.7      evaluate_0.14
duckmayr
  • 16,303
  • 3
  • 35
  • 53
  • Hmmm...so when I strip everything except the title, your approach works, so I'll mark it as the chosen answer. Thanks! However, when I include the other aspects--author, bibliography, abstract, etc. exactly as above--it no longer prints. So you must be running something I'm not...I saw that Pandoc is automatically installed with Rstudio. I updated knitR and Rmarkdown...are there other essential packages that I could be missing when I updated to the latest version of R? – James Jul 15 '20 at 23:41
  • @James I added an update showing exactly what R markdown I ran, as well as a screenshot of the output and my session info in case different packages or different package versions are to blame. Do you get the same error when you have the title fixed but are also including your other YAML? – duckmayr Jul 15 '20 at 23:48
  • Thanks--using a tab/space (as you did) under the abstract, got the writing of the abstract to show up. Show ultimately, I was able to get the title and the writing of the abstract. However, I did notice that this was singular to word. When I used html, everything printed out. Also, it seems that the styles.docx that I created for Rmarkdown in word is also being a little wonky, so it looks like this is an markdown to word issue or something of the ilk. Thanks for your help! – James Jul 16 '20 at 00:35
  • Ah got it @James ! Sorry, didn't notice or forgot I had tabbed the Abstract text. Glad you got it sorted, cheers! – duckmayr Jul 16 '20 at 00:51