showing vignettes link upon building and reloading an R package - r

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.

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!

Troublesome package creating

I have some problems with creating package, can you please spot my mistake?
I followed instruction below :
1.Create functions I want in my package
2.Open new project -> R package
3.Create as many R documentation as many functions I implemented, and then put them into man folder
4.Press Ctr+Shift+B to install package.
The warning I'm facing is
Warning: C:/Program Files/R/R-3.6.3/library/mypackage/man/myfun2.Rd:62: All text must be in a section
I search internet about solution to that problem but I found only involved instructions containing other approach. Is there possibility how to fix this ? Or other approach with using other packages is crucial (as roxygen).
Thanks in advance
You should not write the manual pages yourself. You should use roxygen code to write the manual elements in your function R files, then use devtools::document() to generate the manual pages. See here for examples: https://keithmcnulty.github.io/r_package_training/index.html#1

Unable to generate help files from R package

I have created a package in R. It is all fully documented and written according to R package guidelines. I have used devtools to generate documentation.
document("/home/rstudio/EndoMineR/")
However when I try to use ?EndoMineR I get the error:
No documentation for ‘EndoMineR’ in specified packages and libraries:
you could try ‘??EndoMineR’
How can I create the help files for my package? What am I likely to be missing?
As additional information, when I click the package name in R studio I get the help files but not if I try ?EndoMineR. Also the .Rd files in the man directory (which I think is what devtools::document() generates) seem to be updating just fine. I assume the ?EndoMiner accesses the man files so I'm not sure why this folder is not accessible (it is top level)

How do I fix errors from R CMD check --as-cran to get my R package accepted on CRAN?

Executive Summary
I need assistance to fix the errors as I attempt to create a manual for a new R package. I have created an R package on my computer that I would like to distribute. At the moment, the package is available as a repository on GitHub (http://www.github.com/greenspb/poker), but I want to contribute it to the Comprehensive R Archive Network. I wrote the code years ago, but never shared it out of fear. This is my first repository on GitHub and my first submission to CRAN. I have researched how to get my package on CRAN by reading a blog post at http://kbroman.org/pkg_primer/pages/cran.html . I am stuck on step 1:
"Run R CMD check --as-cran and eliminate all problems. If there are any errors or warnings, your package will not be accepted at CRAN. And even a “Note” will likely disqualify you. So figure out what all of those errors, warnings, and notes mean and then revise your package so that they are no longer issued."
The report generated by "Run R CMD check --as-cran poker" for my "poker" package ( available as a repository on GitHub ) contains errors. My concern is failure to make the LaTeX manual.
Resolved Issues
I used roxygen2 comment tags in the .R file in the project's R folder. roxygen2::document() successfully translated \cr in a comment tag into a new line in the LaTeX file, however it unsuccessfully translated every empty \tab in a comment tag into {} [empty curly parentheses] in the LaTeX file. This happened in dozens and dozens of instances. The \tabular environment was used in an attempt to preserve formatting. I was able to clean up LaTeX errors whenever "There was no line here to end" by searching for {} and replacing appropriate instances with \\{}.
Unresolved Issues
I have no idea how to solve the LaTeX error "Rd2.tex: File Ended while scanning definition of \LT#xxiii", although I believe \LT stands for long table. I am only able to make pdf manuals of several individual functions using R CMD Rd2pdf on the .rd documentation files.
My code is documented using roxygenize tags. When I execute the Run R CMD check --as-cran command, R encounters errors and warnings and fails to make the pdf for the entire package. I need assistance to fix the errors in the report. I want to get my package on CRAN.
See Also
Question on r-package-devel#r-project.org mailing list.
Removing comments on the local variables was the answer to fixing the errors ( replying to #Dason). Thank you.

What type of object is an R package?

Probably a pretty basic question but a friend and I tried to run str(packge_name) and R threw us an error. Now that I'm looking at it, I'm wondering if an R package is like a .zip file in that it is a collection of objects, say pictures and songs, but not a picture or song itself.
If I tried to open a zip of pictures with an image viewer, it wouldn't know what to do until I unzipped it - just like I can't call str(forecast) but I can call str(ts) once I've loaded the forecast package into my library...
Can anyone set me straight?
R packages are generally distributed as compressed bundles of files. They can either be in "binary" form which are preprocessed at a repository to compile any C or Fortran source and create the proper headers, or they can be in source form where the various required files are available to be used in the installation process, but this requires that the users have the necessary compilers and tools installed at locations where the R build process using OS system resources can get at them.
If you read the documentation for a package at CRAN you see they are distributed in set of compressed formats that vary depending on the OS-targets:
Package source: Rcpp_0.11.3.tar.gz # the Linus/UNIX targets
Windows binaries: r-devel: Rcpp_0.11.3.zip, r-release: Rcpp_0.11.3.zip, r-oldrel: Rcpp_0.11.3.zip
OS X Snow Leopard binaries: r-release: Rcpp_0.11.3.tgz, r-oldrel: Rcpp_0.11.3.tgz
OS X Mavericks binaries: r-release: Rcpp_0.11.3.tgz
Old sources: Rcpp archive # not really a file but a web link
Once installed an R package will have a specified directory structure. The DESCRIPTION file is a text file with specific entries for components that determine whether the local installation meets the dependencies of the package. There are NAMESPACE, LICENSE, and INDEX files. There are directories named '/help', '/html', '/Meta', '/R', and possibly '/libs', '/demo', '/data', '/unitTests', and others.
This is the tree at the top of the ../library/Rcpp package directory:
$ ls
CITATION NAMESPACE THANKS examples libs
DESCRIPTION NEWS.Rd announce help prompt
INDEX R discovery html skeleton
Meta README doc include unitTests
So in the "life-cycle" of a package, there will be initially a series of required and optional files, which then get processed by the BUILD and CHECK mechanisms into an installed package, which than then get compressed for distribution, and later unpacked into a specified directory tree on the users machine. See these help pages:
?.libPaths # also describes .Library()
?package.skeleton
?install.packages
?INSTALL
And of course read Writing R Extensions, a document that ships with every installation of R.
Your question is:
What type of object is an R package?
Somehow, I’m still missing an answer to this exact question. So here goes:
As far as R is concerned, an R package is not an object. That is, it’s not an object in R’s type system. R is being a bit difficult, because it allows you to write
library(pkg_name)
Without requiring you to define pkg_name anywhere prior. In contrast, other objects which you are using in R have to be defined somewhere – either by you, or by some package that’s loaded either explicitly or implicitly.
This is unfortunate, and confuses people. Therefore, when you see library(pkg_name), think
library('pkg_name')
That is, imagine the package name in quotes. This does in fact work just as expected. The fact that the code also works without quotes is a peculiarity of the library function, known as non-standard evaluation. In this case, it’s mostly an unfortunate design decision (but there are reasons).
So, to repeat the answer: a package isn’t a type of R object1. For R, it’s simply a name which refers to a known location in the file system, similar to what you’ve assumed. BondedDust’s answer goes into detail to explain that structure, so I shan’t repeat it here.
1 For super technical details, see Joshua’s and Richard’s comments below.
From R's own documentation:
Packages provide a mechanism for loading optional code, data and
documentation as needed.…A package is a directory of files which
extend R, a source package (the master files of a package), or a
tarball containing the files of a source package, or an installed
package, the result of running R CMD INSTALL on a source package. On
some platforms (notably OS X and Windows) there are also binary
packages, a zip file or tarball containing the files of an installed
package which can be unpacked rather than installing from sources. A
package is not a library.
So yes, a package is not the functions within it; it is a mechanism to have R be able to use the functions or data which comprise the package. Thus, it needs to be loaded first.
I am reading Hadley's book Advanced-R (Chapter 6.3 - functions, p.79) and this quote will cover you I think:
Every operation is a function call
“To understand computations in R, two slogans are helpful:
Everything that exists is an object.
Everything that happens is a function call."
— John Chambers
According to that using library(name_of_library) is a function call that will load the package. Every little bit that has been loaded i.e. functions or data sets are objects which you can use by calling other functions. In that sense a package is not an object in any of R's environments until it is loaded. Then you can say that it is a collection of the objects it contains and which are loaded.

Resources