R Sweave Bibtex Citations

I am writing and have been writing several documents using Sweave. In the past, I have been able to create a .bib file and cite using the natbib package with apa styling. Since updating (to enjoy the lovely jobs feature) I can not compile my old .rnw files that used to work.

I've spent hours searching (like this person) around and the only solution that has worked is to open the .tex file that is generated and compile there (this works flawlessly in both cases below). However, using two programs is less than ideal and I'd like to get RStudio to build the pdf directly.

There was some discussion online that perhaps RStudio is not running the BibTex command to create the .bbl file. This seems to be correct because after I build the pdf in TeXStudio (which creates the .bbl file) RStudio will use it and build the pdf properly and fail again once the .bbl file is deleted or moved.

Another approach that seems to work is to

  1. Compile pdf to create the .aux file (it fails)
  2. Run bibtext on the filename in the terminal to create the .bbl file
  3. Compile pdf (it fails)
  4. Compile pdf (it works)

This seems to make it pretty clear that bibtex isn't being run.

Global Settings:

  • Weave Rnw files using knitr (doesn't work with sweave either)
  • Typeset Latex into PDF using pdfLaTeX (doesn't work with XeLaTeX either)
  • Clean auxiliary output after compile is checked (unchecked for the terminal solution above that requires the aux file.)

METHOD 1:

BIB:

@article{majumder2017,
  title={Higher Rates Of Hate Crimes Are Tied To Income Inequality},
  author={Majumder, Maimuna},
  journal={FiveThirtyEight. Last modified January},
  volume={23},
  year={2017}

RNW:

\documentclass{article}
\usepackage{natbib}
\bibliographystyle{apalike}
\begin{document}
  I want to cite this \cite{majumder2017}.
\bibliography{bib}
\end{document}

METHOD 2:

RNW:

\documentclass{article}
\usepackage{natbib}
\usepackage{filecontents}
\bibliographystyle{apalike}
\begin{document}
  I want to cite this \cite{majumder2017}.

\begin{filecontents}{bibliography.bib} 
@article{majumder2017,
  title={Higher Rates Of Hate Crimes Are Tied To Income Inequality},
  author={Majumder, Maimuna},
  journal={FiveThirtyEight. Last modified January},
  volume={23},
  year={2017}
}
\end{filecontents}
\bibliography{bibliography}
\end{document}

Ran on two other computers -- looks like it's something on my end but I checked and the Sweave Global Settings are identical, RStudio versions are too. Both machines use MikTeX. Is there a way to clear RStudio? I just uninstalled, but when I reinstalled it still opened the R files I had open before the uninstall.

Update: I uninstalled again, I deleted the application data in
C:\Users\USER\AppData, and I reinstalled. It still doesn't work.

I just reformatted my machine, reinstalled everything and it still isn't working. HELP!

I uninstalled MikTeX and installed TinyTeX and now it works -- no idea why. Looks like all my other .tex files are running okay for now too. Really weird, but I feel lucky to have randomly gotten it to work.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.