Package development : location of pdf manual and vignette - r

When building mypackage, everything seems to work:
library(devtools)
build(vignettes = T, manual = T)
* checking for file ‘/storage/Documents/client/validate/mypackage/DESCRIPTION’ ... OK
* preparing ‘mypackage’:
* checking DESCRIPTION meta-information ... OK
* installing the package to build vignettes
* creating vignettes ... OK
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building ‘mypackage_0.1.tar.gz’
[1] "/storage/Documents/client/validate/mypackage_0.1.tar.gz"
However I can't find neither the PDF manual nor the vignette.
Vignette: followed workflow as described here, using RStudio / devtools / markdown. However:
vignette("mypackage")
Warning message:
vignette ‘mypackage’ not found
For the PDF manual I have tried this, but no success.
So, my question is: where can I find the PDF manual and the vignette?

I can find my PACKAGE-manual.pdf, where throughout PACKAGE is my package name, by first going to
C:\Users\USERNAME\AppData\Local\Temp\
within the Windows folder directory. You may have to enable hidden folders and files to see this. Within this folder are many many temp folders and other such things. Sort by date, and scroll down to where the folders are. The most recent one is the one you probably want; the ones that prefix with a "Rtmp" are the ones created by R.
Within the (probably) most recent Rtemp[blah] should be a folder entitled PACKAGE.Rcheck. In that PACKAGE.Rcheck folder should be the manual pdf PACKAGE-manual.pdf, assuming it was successfully created.
The full path string on my computer (for this package-creation run) is
C:\Users\USERNAME\AppData\Local\Temp\RtmpG0713j\PACKAGE.Rcheck\PACKAGE-manual.pdf.
You might have to search through a couple of Rtmp[blah] folders before you get the right one.

Not sure quite where RStudio puts it, but in a bare bones check operation the pdf version of the manual should be in a folder called mypackage.Rcheck If you created a mypackage-package.R file then when the package is installed, ?mypackage should lead you to the html version of the manual. The vignette you can get by installing your package and doing vignette("mypackage").

I don't know for the manual, but if you build from rstudio using the 'build and reload' button (nearby the check buttonl, the vignettes, if properly built, should end up in 'yourpackage' subfolder of your r library folder, i think in inst/doc sub sub folder.
Also, for vignettes did you try building them using devtools::build_vignettes ? Usually works for me.

Related

Why the vignette of my package is disapearing after a few time?

I encounter an issue regarding the vignette of a package I am developping in R. Vignette had been created using usethis::use_vignette. It is a Rmd file in the vignettes directory, and the DESCRIPTION file has the following inside :
Suggests:
testthat,
knitr,
rmarkdown
VignetteBuilder: knitr
The check throws one warning, but I think it isn't relevant ("'qpdf' is needed for checks on size reduction of PDFs")
Then I build my source package, and obtain a .tar.gz archive. When I install this (either with the graphic interface of RStudio or with install.packages), my vignette appears if I use ??my_package and is listed when I call vignette(). The installation process also mentions "installing vignettes" and everything seems ok.
However, after a few times the vignette just disapear, and is not findable anymore (or listed). I have not been able to determine what trigger this (this may be after a reboot but not always, sometimes this happens fast sometimes after a few hours...).
I am a bit confused with this, does anyone have an idea?
Many thanks to you!

R package vignettes

I am a little confused as to why there are multiple possible locations for "vignettes" in an R package. I don't understand which locations are used for what and when. For example:
devtools::use_vignettes()
creates a vignettes folder under the root of the package
devtools::build_vignettes()
creates a inst/doc folder that gets promoted to the root at build
pkgdown::build_site()
creates a docs folder.
As background:I have read H.Wickhams R packages book and I have created several packages using the first option and all things have behaved well. I would have users install from github using:
devtools::install_github(pkg,build_vignettes=TRUE)
Now, I have just started to contribute in the joint development of a package in which the first and third option have been used. I have noticed that the .rmd file in the vignettes folder is the same as the index.html file in the docs folder. Does pkgdown copy from the vignettes folder?
Also for this package when i install from github (with build_vignettes=TRUE) i get an error saying installation failed because the doc/index.html path couldn't be found. Now why would that happen?
Vignettes development
There is only one place to put raw vignettes, it is in the vignette directory at the root. This is the place where you write your Rmd file with text and code examples, when developing your package.
Build vignettes for your users
When you build your vignettes, the Rmd file will be knit. The resulting html file, the raw Rmd file and the extraction of the R code will be three files saved in the inst/doc directory. This is what will be kept in the package installation. This is what users will be able to read.
{pkgdown}
{pkgdown} is using your Rmd files of the vignette directory to knit html files so that it can build a website for your package. It also build a page for the list of functions and a index from the Readme file that is also used for your git repository. This is not supposed to stay in the R package, and not accessible to the users. This is to present your package on the Internet.
Conclusion
Hence, when you develop, you only write your Rmd vignette in the vignette directory. The others will automatically keep what they need.

After running R CMD Check, the mypackage.Rcheck directory with PDF manual disappeared

I have installed Rtools v.31 and MKTeX2.9 on my laptop before building my R package. After I ran R CMD check, a directory called mypackage.Rcheck and the source file mypackage_1.x.tar.gz appeared, and while RStudio build package function is checking everything, there is no warning or error message, but at the end when it said (as follows), the corresponding mypackage.Rcheck directory which is supposed to contain the PDF manual disappeared:
checking PDF version of manual ... OK
DONE
NOTE: There were 3 notes.
See
'C:/.../package/mypackage.Rcheck/00check.log'
for details.
R CMD check succeeded
I thought it might be a version conflict between Rtools and R because I'm using R13.1.2 and Rtools v.31, where on the http://cran.r-project.org/bin/windows/Rtools/ website, it said the image isn't frozen (which I don't understand what it means). But I tried all the suggested compatible version pairs between Rtools and R, and still couldn't get it working. So I think this disappearing of mypackage.RCheck is not due to version conflict.
I don't think it's MiKTeX problem because apparently pdf is generated, but was consequently removed. I also tried using --options in R CMD check, but there is no way to force generation of pdf manual, plus pdf was generated at one point. I also read one post on this website, suggesting the use of Rutils function Rd2pdf: "R CMD Rd2pdf mypackage", but I can't run in on windows, and Rutils package is not available for R13.1.2.
can someone suggest the source of the problem or if they have seen this problem before and was able to fix it?
In RStudio: Tools -> Global Options -> Packages. There is a setting "Cleanup output after successful R CMD Check". If this is checked it removes the package.Rcheck folder after a successful check. If you uncheck this setting, the package.Rcheck folder is not removed and you will find the reference manual pdf there.
A common problem for mysterious disappearances of files from R tarballs is to accidentally specify that they should be ignored in the .Rbuildignore file. The lines in that file are regular expressions, so leaving off the anchors ^ and $ can cause them to match more files than you intended. For example,
vig.e
matches vignette.pdf (because there are no anchors to the start and end of the name, and the
dot means "any character".

Files in Collate field missing from package when installing from Github

Note: I cross-posted this question here: https://github.com/hadley/devtools/issues/245
Update: #hadley just closed the issue since he can install now. I have tested it just now and install_github works on Windows too. Apparently I need wait for some time for Github archive to include the new committed changes. For people encounter the same problem, #hadley pointed out that I have .R and .r files in R/ and all the files in DESCRIPTION collate have .r extensions.
I am writing an R package and put it on Github. I can build and load on my own computer. However, after running install_github("KineticEval",username="zhenglei-gao"), I got the following error:
* installing *source* package 'KineticEval' ...
** R
Error in .install_package_code_files(".", instdir) :
files in 'Collate' field missing from 'C:/Users/z.gao/AppData/Local/Temp/RtmpUzWWYn /R.INSTALLd3c17515a0/KineticEval/R':
kingraph.r
kinplot.r
FOCUS2006A.r
FOCUS2006B.r
FOCUS2006C.r
FOCUS2006D.r
modFit1.r
IRLSkinfit.full.r
mkinfit.full.r
ERROR: unable to collate and parse R files for package 'KineticEval'
* removing 'C:/Users/z.gao/R-dev/KineticEval'
A related question is here: Files in Collate field missing from package after build from incorrect .Rbuildignore file
But I can't figure out whether the error is also related to my .Rbuildignore file.
For people encounter the same problem, Hadley(from Github) pointed out that I have .R and .r files in R/ and all the files in DESCRIPTION collate have .r extensions. I use roxygenize to generate the collate field in DESCRIPTION.
What I did is deleting all files in R/ in the local repository and copy back, push it to Github. Only renaming .R as .r under Windows does not change the remote repository. Then the error occured again afterwards so I asked here to see if there is something more I should fix. But after a day, the error disappeared.
I had the exact same problem. I had a silly mistake in my .Rbuildignore. The file I was missing was named something like OutputPlotGenerator.R, and my .Rbuildignore file included the line output, thus removing / ignoring my R file.
For some reason I had the same name twice in my description. One with a .r extension, one with .R as an extension. Removing the wrong one solved the issue.
For me, I had a new .R file which I had not added to the collate field in the DESCRIPTION file.
Simply adding it to that field solved the problem.
Hadley talks about it in a few places here.

showing vignettes link upon building and reloading an R package

I have created a vigentte folder for an R package I am developing by running the code devtools::use_vignette("my-vignette"). I am using Rmarkdown and knitr packages.
When I build & reload the package, I don't get a hyperlink for the title of the Rmarkdown file (which contains the long-form documentation of the package) in the documentation page of the package. I do get hyperlinks for the DESCRIPTION file of the package as well as the help pages of the documented functions but not the hyperlink that should direct people to the Rmarkdown document. I am wondering why and what should I do to get a hperlink for the long-form documentation of the package in a similar way that I get it for the help pages for the functions used in the package?
Daragh,
Can you provide more detail on the error you are seeing? If the code is posted on github or you have a specific error then we may be able to help further - if not then the best advice I can give is to check out Hadley Wickam's "R Packages" book online - it is a great reference:
http://r-pkgs.had.co.nz/
that will at least give you a good sense of how to build the vignettes.
http://r-pkgs.had.co.nz/vignettes.html
From the online book by Hadley Wickham referenced above...
CRAN notes
Note that since you build vignettes locally, CRAN only receives the html/pdf and the source code. However, CRAN does not re-build the vignette. It only checks that the code is runnable (by running it). This means that any packages used by the vignette must be declared in the DESCRIPTION. But this also means that you can use Rmarkdown (which uses pandoc) even though CRAN doesn’t have pandoc installed.
Common problems:
The vignette builds interactively, but when checking, it fails with an error about a missing package that you know is installed. This means that you’ve forgotten to declare that dependency in the DESCRIPTION (usually it should go in Suggests).
Everything works interactively, but the vignette doesn’t show up after you’ve installed the package. One of the following may have occurred. First, because RStudio’s “build and reload” doesn’t build vignettes, you may need to run devtools::install() instead. Next check:
The directory is called vignettes/ and not vignette/.
Check that you haven’t inadvertently excluded the vignettes with .Rbuildignore
Ensure you have the necessary vignette metadata.
If you use error = TRUE, you must use purl = FALSE.
You’ll need to watch the file size. If you include a lot of graphics, it’s easy to create a very large file. There are no hard and fast rules, but if you have a very large vignette be prepared to either justify the file size, or to make it smaller.

Resources