# wrong encoding using knitr on bibentry

I'm trying to cite packages used following this code: https://stackoverflow.com/a/43888025/8146116 I change the bibentry style to latex but I get the warning:

Warning: :0-4: Some input could not be re-encoded to ASCII}

with non-english characters

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\let\bold\textbf %this is necessary
\begin{document}
<<r_list, echo=FALSE, results='asis'>>=
citations <- function(includeURL = TRUE, includeRStudio = FALSE) {
if(includeRStudio == TRUE) {
ref.rstudio <- RStudio.Version()$citation if(includeURL == FALSE) { ref.rstudio$url = NULL;
}
print(ref.rstudio, style = 'text')
cat('\n')
}

cit.list <- c('base', names(sessionInfo()$otherPkgs)) for(i in 1:length(cit.list)) { ref <- citation(cit.list[i]) if(includeURL == FALSE) { ref$url = NULL;
}
a=format(ref, style = 'latex')
cat(a)
cat('\\par ')
}
}

library(tidyverse)
citations()
@
\end{document}


Also how can I use RStudio.Version() outside of RStudio?

Welcome to TeX.SE. Nice first question.

Note: This solution requires a working installation of R. Execute in RStudio or alternative editors for knitr.

Step 1. Check your file encoding settings in RStudio. Go to Tools > Code > Saving > Default text encoding and chose UTF-8. Read Yihui's discussion about file encoding here. There is a ç (cedilla) in the name (François) of one of the authors of the dpylr package and if UTF-8 is not set on the file encoding it will generate an error. Use of \usepackage[T1]{fontenc} in the preamble of the tex file is also recommended.

Step 2. The R chunk produces a list of loaded packages. For each package, the citation is retrieved by combining the base package with the packages listed in names(sessionInfo()$otherPkgs), using the function citation. The structure of the output from the citation function is a list. This is converted to a variable ref with a BibEntry structure using the as.BibEntry function from the RefManageR package. ref is then written to a bib file using the WriteBib function, also from the RefManageR package. Step 3. From there, LaTeX takes over. The bib file is declared in the preamble using \addbibresource. The formatting is done using biblatex and Biber. All the package citations are output using \nocite{*} and \printbibliography. There are two particular benefits of this approach versus the original method. First, the bib file is written to disk. It can be imported into a bibliographic database (e.g. JabRef) and manipulated, if necessary. Second, by invoking biblatex and biber, we have a lot of control over the formatting of the output, and where the bibliography of packages appears in our document. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{hyperref} \usepackage[margin=2.5cm]{geometry} \usepackage[style=authoryear,backend=biber]{biblatex} \addbibresource{packages.bib} \begin{document} <<r_list,echo=FALSE,eval=TRUE,results='asis',tidy=TRUE>>= tidy.opts = list(blank = FALSE, width.cutoff = 50) library(tidyverse) library(RefManageR) cit.list <- c('base', names(sessionInfo()$otherPkgs))

for(i in 1:length(cit.list)) {
ref <- as.BibEntry(citation(cit.list[i]))
WriteBib(ref,file="packages.bib",biblatex=TRUE,append=TRUE,verbose=FALSE)
}
@
\nocite{*}
\printbibliography
\end{document}


This is the result: