Lost references with “Compile PDF” for a Sweave vignette in RStudio - r

“Compile PDF” in RStudio 0.99.902 with R 3.3.0 cannot find references included in the “sos” Sweave vignette that's been part of the “sos” package on CRAN since 2009. It produces “sos.pdf”, which reads mostly OK, except that the inline references are replace by something like “?”.
For example, an entry “\citet[pp. 282-283]{JC09}” that previously translated into “Chambers (2009, pp. 282-283)” now displays as “?, pp. 282-283”. The “\bibitem[Chambers(2009)]{JC09}” entry is still at the end of the file and prints with the Bibliography, but “Compile PDF” in RStudio cannot find it make the proper substitution for “\citet[pp. 282-283]{JC09}”.
Any suggestion on how to fix this?
Thanks,

Related

Use R/exams exams2pdf() to produce a PDF document

I am new to the R/exams package and I try to produce a pdf document from one of the templates provided by the developers. (http://www.R-exams.org/templates/confint3/)
I am able to compile a Rnw file into a HTML document using the commands
library("exams")
exams2html("confint3.Rnw")
When calling the function
exams2pdf("confint3.Rnw")
it gives the error message
! LaTeX Error: File `Sweave.sty' not found.
I have Latex installed and there are no problems using it in general. I do not understand:
Do I need to tell exams2pdf() the location of the latex installation?
Do I need to define a template (as plain.tex) first? How should it look like?
What is it that I do not understand?
I looked at the documentation of the exams package, I also tried exams2pdf() after installing and calling library("tinytex").
Any help where to look at or what to do is highly appreciated. Thank you!
Minimal example:
install.packages("exams")
install.packages("tth")
library("exams")
set.seed(1090)
exams2html("confint3.Rnw")
set.seed(1090)
exams2pdf("confint3.Rnw")
It is hard to diagnose what exactly goes wrong with the information provided. In any case, when running pdfLaTeX either through utils::texi2dvi() (the default when the R package tinytex is not installed) or through tinytex::latexmk() (the default when the R package tinytex is installed) does not find the Sweave.sty file provided by the R base system. What is not clear to me which LaTeX engine is running in the background: MikTeX on Windows?
There are several strategies that could resolve this issue:
Tell your LaTeX installation about the texmf directory provided by the R base system so that it is found no matter where on your system you call pdfLaTeX.
Use a different LaTeX installation, e.g., by installing TinyTeX (the LaTeX distribution) through tinytex (the R package): tinytex::install_tinytex(). This might be particularly attractive if you are not actually a LaTeX user and just need it to compile PDF exams.
Avoid using the Sweave.sty file in a custom template file, say myplain.tex. A suggestion for such a file is included at the end of this post.
Further details are discussed in this thread: https://tex.stackexchange.com/questions/153193/latex-error-sweave-sty-not-found
As for your three questions:
As already explained above: exams2pdf() leverages either utils::texi2dvi() or tinytex::latexmk(). So these need to know about the LaTeX installation - but this seems to be the case. They just don't find the texmf provided by base R.
You should not have to do this but it is certainly an option that you can use. As a starting point, run exams_skeleton(markup = "latex", writer = "exams2pdf"). Among other things this creates a templates folder where you could put the myplain.tex template below.
As I said above, it's hard to answer that with the information provided. Hopefully, one of the clues provided here gets you a couple of steps forward.
Content of myplain.tex:
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{a4wide,graphicx,color,verbatim,url,fancyvrb,ae,amsmath,amssymb,booktabs,longtable,eurosym}
\newenvironment{question}{\item \textbf{Problem}\newline}{}
\newenvironment{solution}{\textbf{Solution}\newline}{}
\newenvironment{answerlist}{\renewcommand{\labelenumi}{(\alph{enumi})}\begin{enumerate}}{\end{enumerate}}
\providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setkeys{Gin}{keepaspectratio}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}
\newenvironment{Schunk}{}{}
\begin{document}
\begin{enumerate}
%% \exinput{exercises}
\end{enumerate}
\end{document}

Using accented letters in R package documentation using bibtex and roxygen2

I am developing an R package in RStudio (R version 3.6.1; RStudio version 1.2.1335) using roxygen2 (version 6.1.1) and am using the \insertCite{} command together with a bibtex file in order to cite references in the documentation for individual functions. I am following the instructions Inserting references in Rd and roxygen2 documentation. Everything works fine, except when I try to include a reference with accented characters. So my REFERENCES.bib file contains the following entry:
#ARTICLE{Cabcdef15,
author={John {\c C}abcdef},
title={A title},
journal={Journal of Applied Stuff},
year={2015},
volume={81},
number={1},
pages={100--200},
}
The {\c C} is the LaTeX command for a C-cedilla (Ç). (I also tried \c{C} and pasting Ç directly and neither resolved the issue.)
I cited this reference in the roxygen2 preamble for my R function myfunction using \insertCite{Cabcdef15}{mypackage}. However, in the documentation output (after running devtools::document() and devtools::build(), installing the package and running library(mypackage) and ?myfunction) the citation appears in my browser (Google Chrome) as (Çabcdef 2015) rather than as (Çabcdef 2015).
Presumably this is an encoding issue. However, from what I read in the aforementioned instructions (under 4.4 Encoding of file REFERENCES.bib) this should be working, provided that I have the line Encoding: UTF-8 in the DESCRIPTION file for my R package, which I do. Hence I am stumped.
I have a strong suspicion you are using a Microsoft operating system.
I have code in a roxygen2 examples block which outputs accented French characters: works fine with non-French locales on MacOS and Linux: Windows makes a mess of it. I have UTF-8 in package DESCRIPTION. For me, the obvious work-around is not to use Windows for documenting the package. UTF-8 everywhere seems to work well for me, except on Windows. The R documentation links are helpful, and, in a related post, the mighty Yihui Xie writes about this issue.
This WONTFIX R issue also hints at the root cause: Windows.
A more palatable and Windows-compatible workaround is discussed in platform specific sections in Writing R Extensions.

R Sweave does not compile .bbl file

R Sweave does not compile automatically the .bbl file necessary to detect citations in the text. I found a solution with compiling in another program (https://community.rstudio.com/t/impossible-to-cite-with-biblatex-in-r-sweave/35008/2) but it would much more convenient not to compile three times the same file (on two different softwares).
One of the comments here (RStudio will not write a .bbl file when compiling .Rnw file with citations in natbib) mentioned the fact that maybe R Sweave does not run bibtex. Is there something to do to fix this problem ?
(Question also asked here : https://community.rstudio.com/t/r-sweave-does-not-create-a-bbl-file-on-linux-ubuntu/35110)
I finally got the solution, here's what I did :
based on the comments of user1329307, I uninstalled MikTeX and the complete TeX distributions on my computer. Since I use Ubuntu, I used purge to remove MikTeX, TeXLive, tex-commons, etc.
then, I installed (or re-installed) TinyTeX (details here)
I installed manually the packages I needed with tlmgr_install(). Normally, it can be done automatically but that's what I did.
finally, I replaced biber by bibtex in \usepackage[backend = biber]{biblatex} (this person explains why it is important)
This last step made it work, but I don't know if the previous ones are important or not. Since user1329307 succeeded in compiling the bibliography too, I suppose it is necessary but there's no way for me to prove it.
Anyway, now, when I compile the Sweave document, the bibliography is directly created. Thanks a lot to user1329307 for his/her ideas.
Edit : I re-installed MikTeX after all of this and it works too.

compiling legacy Sweave with RStudio 0.99.902

I'm having multiple problems with the “sos” vignette in the “sos” package that has been on CRAN since 2009. I recently noticed that it fails in multiple ways, and I can't figure out how to fix several of the problems. "Compile PDF" on “sos.Rnw” in RStudio with R 3.3.0 under Mac OS X 10.11.5 produced an XQuartz pop-up as follows:
>Sweave Noweb Syntax?
>>It seems you are using the Sweave-specific syntax in line(s)
>>9, 15, <snip>; you may need Sweave2knitr("sos.Rnw") to
>>convert it to knitr'.
I did the following, as it asked:
Sweave2knitr('sos.Rnw')
This produced a file 'sos-knitr.Rnw'. I opened this file in RStudio and clicked 'Compile PDF'. I got one line only:
>Loading required package: knitr"
If I got anything else, I don't know where it went.
Any suggestion on how I can get past this?
Thanks, Spencer Graves
RStudio is using knitr by default instead of sweave to generate the code. Revert this decision by doing the following:
RStudio:
Tools -> Global Options -> Sweave -> Weave Rnw files using: Sweave

R documentation, how to force Rcmd Rd2pdf to automatically break an overfull line in examples R-like section?

My package passed Rcmd check successfully. but in constructed PDF format of R documentation, within the examples section, half of the line (R code) is out of the paper. I also found another CRAN submitted package, ftsa , that suffer from overfulling in a line too, see ftsa Reference manual.
I guess this
problem roots in the behavior of the verbatim environment in Latex. However there are some Latex packages to deal with this, https://tex.stackexchange.com/questions/14342/verbatim-environment-that-can-break-too-long-lines, but I do not know how to use them with Rcmd.
In dealing with these cases, why Rcmd check does not show any error, warnings or note as Latex does?
How can I force line breaking in examples section?
Thank you
R CMD check does not analyze / forward all LaTeX warnings. Yes, in an ideal world it would.
It has been the case, always that you should format the \examples{ ... } section
well, yourself,
notably including sensible line breaks (and leading spaces) for nice alignment of multi -line examples.
Use the sources of R itself or recommended packages (or those authored by me, as I do pay attention to this quite a bit), to see good examples in their *.Rd files.
Remember: The current development sources of R are always web accessible at
R (devel) source tree # svn.r-project.org, i.e. R's standard packages at R sources src/library.

Resources