0

I'm trying to knit together a draft of a paper and I have knitr is rendering a jpeg plot I created elsewhere and saved in another folder. Ultimately, I want to cross-reference this figure with like 20 others in a manuscript draft, but I can't get the draft to render as a pdf.

Here is the text and the r chunk code:


    To get a sense of what these patterns have looked like at the neighborhood level within metro areas across the country, I merge two decades of census tract-level data with the US Census Core-Based Statistical Areas (CBSA) delineation files from March 2020 [-@USCensusBureau2021] to identify all tracts located all 384 metropolitan areas across the country. Following previous literature and a desire for parsimony, I limit the scope of my analyses to the largest 100 metro areas by their 2019 population [@Acevedo-Garcia2016; @Krysan2017; @Pais2012]. 
    
    Figure lists the largest 100 metro areas in both 2000 and 2019 by population. In both years, we see many of the same metro areas at the top, with the three largest metros (New York, Los Angeles, and Chicago) each several times larger than the remaining 97 metros. Looking at 2019, the New York metropolitan area is home to approximately 19,294,236 people and is almost as large as Los Angeles (13,249,614) and Chicago (9,508,605) combined. Dallas and Houston are the two next largest metro areas, book-ending 7 million people. The Washington, Miami, Philadelphia metro areas have over 6 million people, with Atlanta close behind at 5.8 million. There are five metro areas with populations around 4 million. From there, we begin to see more clustering in population size with several metro areas having populations of 3,000,000, 2,000,000, and 1,000,000. It isn't until Tulsa, the 55th largest metro area where metro populations drop below 1 million and we see smaller differences in population between metros. 
    
    
    See Figure \@ref(fig:rank-chg)
    
    ```{r rank-chg, fig.cap = "Rank Change"}
    
    knitr::include_graphics(here("output/figures/chapter1/top100/alluvial.jpeg"))

and here is the YAML header and chunk options at beginning of my script that I plan to eventually fill out:


    ---
    title: "Chapter 1: Introduction"
    author: "Kasey Zapatka"
    date: " lasted edited: `r format(Sys.time(), '%B %d, %Y')`"
    output:
      bookdown::pdf_document2:
        toc: no
        fig_caption: yes
        latex_engine: xelatex
        keep_tex: true
    bibliography: "references/chapter1.bib"
    link-citations: yes
    fontsize: 12pt
    header-includes:
        - \usepackage{rotating}
        - \usepackage{setspace}
        - \newcommand{\beginsupplement}{\setcounter{table}{0}  \renewcommand{\thetable}{A\arabic{table}} \setcounter{figure}{0} \renewcommand{\thefigure}{A\arabic{figure}}}
        - \usepackage{lineno}
        - \linenumbers
        - \setlength\parindent{24pt}
    abstract: |
      In this first chapter, I will 
    ---


    knitr::opts_chunk$set(
      fig.align = "center",        # center align figures
      fig.keep = "all",            # keep all figs
      warnings = FALSE,            # prevents warnings from appearing in code chunk
      message = FALSE,             # prevents messages from appearing in code chunk
      echo = FALSE,                # do not echo code in file
      results = "markup"           # hide results
    )

The figure appears when I execute the code chunk but it says it can't find the image. here's the error:


    ! LaTeX Error: File `/Users/Dora/Library/Mobile Documents/com\nobreakspace {}ap
    ple\nobreakspace {}CloudDocs/doctorate/dissertation/output/figures/chapter1/top
    100/alluvial' not found.
    
    Error: LaTeX failed to compile test.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See test.log for more info.
    Execution halted

I'm at loss. I thought the error was because the file path is through iCloud and has some spaces, but I can't get the file to render saved elsewhere with not spaces at all in the file path. When I generate the file in the code chunk instead of just introducing the figure with knitr::include_graphics, it works, but I have like 20 figures so I'd prefer to just use the knitr::include_graphics function to streamline the manucscript write up.

Any help would be appreciated. I know this is possible bc it's described here. Here' a link to the image, the test.Rmd file, and reference to compile.

kaseyzapatka
  • 149
  • 2
  • 9
  • What is the error with the pathname without spaces ? – CALUM Polwart Oct 11 '21 at 18:40
  • @CALUMPolwart. So, when I moved it to another Rproject, it worked. I think it's an issue of file paths have spaces/weird symbols bc files are saved on iCloud. Never had issue w/this before but is a problem knitting together pdf_document2. Any suggestions? – kaseyzapatka Oct 11 '21 at 19:14

0 Answers0