R building a package gives different output for vignette - r

I am building my first R package and I am facing some problems.
When I run knitr from the Rstudio I get the html vignette as I want it.
However when I run R CMD Build I realize that I have 2 vignettes.
One found in vignettes/vignette.html and the other in inst/doc/vignette.html
Each one of these gives a different result for the vignette, I tried to check the .Rmd for each and changed them to be the same but I still get different results.
The .Rmd file does not reflect the html file being produced for both vignettes?
Any ideas?

Related

Is there a special .Rmd template to create R package vignette in pdf?

I'm developing my first R package and I'm trying to produce a pdf vignette for the package. I have read some documents and online tutorial about producing package vignettes by the tools such as rmarkdown and knitr. I implemented some steps and produced a pdf vignette. However, having a look on the pdf vignettes of some packages like:
https://cran.r-project.org/web/packages/rmarkdown/rmarkdown.pdf
https://cran.r-project.org/web/packages/cluster/cluster.pdf
https://cran.r-project.org/web/packages/lmom/lmom.pdf
https://cran.r-project.org/web/packages/lmomRFA/lmomRFA.pdf
https://cran.r-project.org/web/packages/e1071/e1071.pdf
, it seems that there is a special template to produce pdf vignettes of R packages. Is there such a template? If yes, how can I find and use it?
Thanks in advance for any help
As mentioned in the comments I've mistaken reference manuals as vignettes and so, I hadn't be able to find the correct answer. When I searched by using the correct keywords, I found the correct answer:
https://devtools.r-lib.org/reference/build_manual.html
https://cran.r-project.org/web/packages/Rd2md/vignettes/Introduction.html
R create reference manual with R CMD check

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}

My code will run as a chunk but gives me an error when I try to knit

Hi I'm new to R and I'm using RStudio Cloud for a university stats course.
The code I'm having trouble with will run as a chunk but when I try to knit the project it comes up with an error saying that the object 'filename' not found.
The 'filename' is listed in the global environment but it is a tbl_df, which I'm thinking is not the right kind of object for knitting.
It is difficult to answer without having all the code. And code is almost always better than a screenshot.
My guess is that you loaded the dataset X2019THBrier manually in RStudio. Thus you can access it in chunks, in the current R session, but not in the knitted R session.
You need to write commands to load the data. As you are loading an XLSX file, you might want to install the openxlsx package, and use the openxlsx::read.xlsx() command.

R package knitr misses R chunks

I haven't been able to use the neater knitter package with the code chunks.
Basically there's only a few number of occasions in which it interprets them well, but for the most of it the chunks are not recognized as such. That is:
Running a markdown from RStudio only renders chunks before the file is saved. If the file has been saved, then it will show the code as is: no R output.
I also tried using knitr from within LyX, and this presented other problems. The simplest example knitr.lyx was rendered correctly as a pdf, but not html. Using more complicated documents, like the RJournal template showed other errors.
Rscript --verbose --no-save --no-restore
At first I thought it had to do with my Rstudio installation, but now I'm not so sure anymore.
By the way, I'm on Ubuntu 15.04 and the files that I'm using are examples from the documentation:
Rstudio > New File > Rmarkdown... renders R output only before it's saved.
knitr's manual in LyX from Github repo.
I found the answer for this.
It's very obvious and yet easy to overlook if you don't know it.
The problem was in saving the file with the wrong extension.
If you're using R code chunks you need .Rmd extension in Rstudio.
As I was starting with markdown I was using .md. Pfff.

non-evaluated vignettes with knitr::rmarkdown_notangle

The knitr package has relatively recently added new notangle vignette engines, such as knitr::rmarkdown_notangle, that allow disabling of evaluation of vignette chunks. The general process of using knitr for vignettes is described here, while the specific notangle functionality is described in an answer to this question.
My problem is that I can't get this to work. I can get it to pass R CMD build by including the .html output in the vignettes directory (I also put a copy in inst/doc), but I can't get it to pass R CMD check unless I specify --no-build-vignettes, or unless I change the rmarkdown_notangle engine back to rmarkdown.
I have built a trivial package that contains the following vignette (in vignettes/notangle.rmd): it's available here.
<!--
%\VignetteEngine{knitr::rmarkdown_notangle}
%\VignetteIndexEntry{Supplementary Materials}
-->
A silly little vignette.
```{r}
2+2
```
My DESCRIPTION file includes
Suggests:
knitr,
VignetteBuilder: knitr
BuildVignettes: yes
When I try to run R CMD check I get
* checking re-building of vignette outputs ... NOTE
Error in re-building vignettes:
...
Error: processing vignette 'notangle.rmd' failed with diagnostics:
Failed to locate the ‘weave’ output file (by engine ‘knitr::rmarkdown_notangle’)
for vignette with name ‘notangle’. The following files exist in directory ‘.’:
‘notangle.rmd’
Using r-devel (2014-09-17 r66626), but also happens with 3.1.1.
The workaround (which I would strongly prefer to avoid) is to switch from R code chunks to generic code chunks (opens with triple-backtick, rather than triple-backtick+"r"), which Rmarkdown doesn't process.
I'm sure I'm doing something boneheaded. Any clues?
update: I can get what I need (stop all chunks from being evaluated) by explicitly adding eval=FALSE to the options of every chunk, but I'd still like to know what's going on ...
It is a bug in the current version of knitr, and it has been fixed in the development version 1.7.9, which will (hopefully) be v1.8 on CRAN in the future.

Resources