New install - RStudio, R and TexLive - cannot compile pdf with citations

I have a new Windows 10 Dell laptop (i7 CPU) with the latest Versions of RStudio (Version 1.3.1056), R (4.0.1) and TexLive (2020). I am using knitr to write my reports and it works fine as long as I don't have references, and citations. If these are included in the document, a tex file is created but does not compile. I am using "Weave Rnw files using knitr" and "Typeset LaTeX into PDF using XeLaTeX". If I compile that .tex file in say WinEdt - it works fine and complies the document without any changes.

Here is an example of what I use:

testing.rnw
\documentclass[a4paper, 10pt, fleqn]{article}

\usepackage[paper = a4paper, left = 25mm, width = 160mm, top = 25mm, bottom = 25mm]{geometry}
\usepackage{apacite}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{graphics}
\usepackage[utf8]{inputenc}
\setlength{\parindent}{0em}
\setlength{\parskip}{14pt}
\usepackage{booktabs}
\usepackage[dvipsnames]{xcolor}
\usepackage{colortbl}
\usepackage{longtable}

\usepackage[light]{iwona}
\usepackage[T1]{fontenc}

\begin{document}

A linear mixed model using restricted maximum likelihood were used to
analyse the data using ASReml-R \cite{asremlr}. The model can symbolically be written as:

\begin{center}
\textsf{response \sim Site + Treatment + Site:Treatment + \emph{Replicate} }
\end{center}

\clearpage

\bibliographystyle{apacite}
\bibliography{ref2}
\end{document}

ref2.bib
@Manual{asremlr,
title = {asreml: asreml() fits the linear mixed model},
author = {David Butler},
year = {2009},
note = {R package version 3.0},
url = {www.vsni.co.uk},
}

@Manual{r,
title = {R: A Language and Environment for Statistical Computing},
author = {{R Core Team}},
organization = {R Foundation for Statistical Computing},
address = {Vienna, Austria},
year = {2016},
url = {https://www.R-project.org/},
}

The error says "There were undefined references". I should also say that I have tried using tinytex and Miktex but these have not helped. Can anyone help me to get this working properly, please?

Welcome in the Community.
It would be helpful when you would include the Rmd input.
Then we could could try to recreate and solve your problem in a relatively easy way.

I did include all the code for a working example in the original post but a link to the files is here

I also have problems with compiling the Rnw file to an PDF file.
I could circumvent the problem by replacing apacite by natbib and plain in the Rnw file.
Of course I do not know if this would be acceptable in your situation.
See my copy of the file below. The compile can then be done with

script to compile

Sweave('test.Rnw')
tinytex::pdflatex('test.tex')

adapted Rnw file

\documentclass[a4paper, 10pt, fleqn]{article}

\usepackage[paper = a4paper, left = 25mm, width = 160mm, top = 25mm, bottom = 25mm]{geometry}
\usepackage{natbib}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{graphics}
\usepackage[utf8]{inputenc}
\setlength{\parindent}{0em}
\setlength{\parskip}{14pt}
\usepackage{booktabs}
\usepackage[dvipsnames]{xcolor}
\usepackage{colortbl}
\usepackage{longtable}

\usepackage[light]{iwona}
\usepackage[T1]{fontenc}

\begin{document}

A linear mixed model using restricted maximum likelihood were used to
analyse the data using ASReml-R \cite{asremlr}. The model can symbolically be written as:

\begin{center}
\textsf{response ∼ Site + Treatment + Site:Treatment + \emph{Replicate} }
\end{center}

\clearpage

\bibliographystyle{plain}
\bibliography{ref2}
\end{document}

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