\code{\link{<>}} does not create hyperlink when using roxygen - r

I'm new to Roxygen and using Roxygen to document my functions and scripts (I'm not building a package, but using the package structure in order to be able to use Roxygen). I use Rd2HTML function to translate .Rd to .html. I'm trying to make a hyperlink in one .Rd file to another .Rd file, and maintain that link in the .html file.
Suppose I have two scripts and .Rd files: code1 and code2. When I add \code{\link{code1}} to the roxygen comments of code2, run roxygenize("<location of package>") and use Rd2HTML to built a html file, the result is that the html-file shows code1 instead of code1 at the location of \code{\link{code1}}. In other words: no hyperlink is shown in the html file of code1, instead code1 formatted as code is returned. Adding the package name does not resolve the issue.
Can anyone explain this behavior (and solve my issue :))?
Details:
NAMESPACE file:
# Generated by roxygen2 (4.1.1): do not edit by hand
export(code1)
export(code2)
DESCRIPTION file:
Package: Scripts
Type: Package
Title: What the package does (short line)
Version: 0.0.1
Date: 2012-11-12
Author: Who wrote it
Maintainer: Who to complain to <yourfault#somewhere.net>
Description: More about what it does (maybe more than one line)
License: GPL

I solved the issue myself. I hadn't installed the package and therefore couldn't locate any .html links.
By the way, http://yihui.name/en/2012/10/build-static-html-help/ helped me to easily build .html pages for help pages.

Related

Rpackage, mathjaxr, + check_rhub() returns "Package has help file(s) containing install/render-stage \Sexpr{} expressions but no prebuilt PDF manual"

I'm trying to use the mathjaxr package for my R package documentation. I can locally see the HTML and PDF output of the help file in question and it looks good with mathjaxr::preview_rd("foo", type = "pdf"), pkgdown::build_reference(), etc. However, when I submit my package to devtools::check_rhub(platforms = "windows-x86_64-devel") (or just devtools::check_rhub()), I receive:
* checking CRAN incoming feasibility ... NOTE
Maintainer: 'Name <Email>'
Package has help file(s) containing install/render-stage \Sexpr{} expressions but no prebuilt PDF manual.
I can run R CMD build . and then R CMD check --as-cran mypackage_v.v.v.tar.gz locally and receive Status: OK.
As listed in the mathjaxr documentation I have:
Included mathjaxr in the imports field of the DESCRIPTION file
Included mathjaxr in the RdMacros field of the DESCRIPTION file
Included \loadmathjax in the #description section of each function using mathjaxr
Added #import mathjaxr to the NAMESPACE
This question looks very similar but does not resolve my issue.
Troubleshooting
If I remove everything from the R function's Roxygen skeleton in the relevant .R file except \loadmathjax in the #description section, I still receive the same error. That is, a bare minimum function documentation with just this \loadmathjax macro generates this NOTE.
If I use \loadmathjax{} instead of \loadmathjax, I get the same NOTE.
If I remove \loadmathjax macro but leave everything else (in DESCRIPTION, NAMESPACE, and the \mjtdeqn{}{}{} and \mjeqn{}{} macros in the .R file), I do not receive the NOTE. While I don't expect that my help file will look correct either, I'm not sure how exactly to check this without submitting to CRAN and finding out once accepted.

Edit the default PDF manual generated while building R package

I have succsesfully performed the below steps to create my own R package :
created skeleton of the package and pasted .Rd, NAMESPACE and DESCRIPTION files.
executed R CMD check package_name : no errors, it also generated 2 pdf's
One of which contains the output's from .Rd file examples and second is the PDF manual that comprises the documentation itself.
My question is how to make edits to this manual created, such as to change the font size or add an Introductory page to this manual? I read that roxygen / devtools might help but no resource on that was attained. I also went through the Writing R Extensions link that is available but couldn't help me.
Would there be a way using Rd2pdf? but such that even non .Rd files are also included

rmarkdown::render_site() Error in rmarkdown::render_site() : No site generator found

I am trying to knit together 3 files using this example: http://rmarkdown.rstudio.com/rmarkdown_websites.html
My files all share the same directory, which has been set in the RStudio build options. I literally copied the YML from the examples with my own file names. Even if I copy the examples directly, I get the same error.
I even ran the site_generator function from the RMarkdown Github: https://github.com/rstudio/rmarkdown/blob/master/R/render_site.R#L157
I noticed there are options for custom generators, which I do not want. All I would like to do is be able to knit together several markdown files into a single webpage and then create a navbar with tabs for each page/section.
I got the same error when attempting to build with an incorrectly named YAML config file. Specifically, the RStudio build option for a website requires that the config file be called _site.yml.
Verify that this file exists and that you're using the extension .yml rather than .yaml (even though the latter is preferred).
What helped for me was putting the line site: bookdown::bookdown_site back to index.Rmd.
lord, my issue was that i didn't set my working directly to where my _site.yml file and index.Rmd files are stored - the little things!
I fixed this error using this steps.
1-) RStudio-Tools-InstallPackages
2-) Install From should be CRAN Repository.
3-) write this command --> install.packages("install.packages("rmarkdown")")
4-) Click Install
And problem has gone... And this is output.
This error also appears when there is a format issue in the yaml section of index.Rmd.
In my case, I encountered the error when the opening "---" in index.Rmd had a couple of white spaces " ---".
If you are having this problem, I would recommend knitting index.Rmd by itself (not building the book) before trying anything more drastic.

NAMESPACE not generated by roxygen2. Skipped. - Confusion with Hadley book

I am trying to make a package but when I run document() it prints NAMESPACE not generated by roxygen2. Skipped. I am trying to use ggplot2,XML, R6 packages in my functions. I am importing them in the following way:
#' #rdname visualization
#' #param hist_data A table of weather variables with PWS created by hist_data function
#' #param variable A character string of variable name
#' #examples
#' table <- getWeather(city = "San Francisco", state="CA")
#' please <- getConditionsTable(table, "2015-03-09")
#' tab <- hist_data(table, please)
#' head(tab)
#' plot_variable_across_all_pws(hist_data=tab, variable="tempi")
#' #import ggplot2
#' #import XML
#' #import R6
I am wondering what might be causing this error and there is nothing in my Namespace except for exportPattern("^[^\\.]")
Also, I was going over R packages book by Hadley http://r-pkgs.had.co.nz/namespace.html
And confused by the line :
"Note that you can choose to use roxygen2 to generate just NAMESPACE, just man/*.Rd, or both. If you don’t use any namespace related tags, roxygen2 won’t touch NAMESPACE. If you don’t use any documentation related tags, roxygen2 won’t touch man/."
Is this what I'm doing wrong? or missing?
Backup NAMESPACE file, if you need it for future use
Delete the NAMESPACE file
Run devtools::document(), so that roxygen2 will generate new NAMESPACE file in the package source directory
*** make sure you have #export tag in the roxygen2 doc section of the R source file.
I think that devtools tries to avoid overwriting DESCRIPTION and NAMESPACE files that it didn't generate itself (to avoid angst if you have meticulously typed them in yourself, instead of using embedded roxygen comments in your r code). It isn't always possible but it tries.
The main mechanism, as I understand it, is to post a comment at the top of the file when it generates the file, and then later on, look for that comment (there are tricky bits round the edge, for example if you use #includes to create the Collate order in the DESCRIPTION file, but I don't think that is your problem here.)
An example of such a comment is
# Generated by roxygen2 (4.1.0.9001): do not edit by hand
The not generated by ... message is alerting you to this, and letting you know devtools is not going to use roxygen2 to make a NAMESPACE file for you. You possibly have the one you mention without the comment because you used RStudio to start your package, rather than devtools::create() ?
If you just delete the NAMESPACE file, I think devtools::document() would then work for you.
BTW You have a typo in the example code above (you have#' #import ggplo2 instead of #' #import ggplot2)
Thanks to #jsta's solution and I copied the following line # Generated by roxygen2: do not edit by hand at the top of the NAMESPACE file, and then with an empty line.
Then I ran devtools::document() in the console and it automatically replaced the existing NAMESPACE file.
I think that top line is just what roxygen will look for to see if that file is generated by roxygen.
None of the preceding examples worked for me. If I deleted the NAMESPACE file then roxygen complained there was no NAMESPACE. If I deleted and re-created a NAMESPACE file (with `touch, e.g. RStudio: Building package with roxygen2. Not producing NAMESPACE file) then roxygen complained that the file was not created with roxygen.
The solution was to copy a NAMESPACE file from another project that was created with roxygen.
Also one may simply delete everything from NAMESPACE and add leave one line: exportPattern("^[[:alpha:]]+")
If the file NAMESPACE is changed manually, devtools::document() fails to overwrite this file, that is why it leaves as before. When you delete the text from the NAMESPACE file and insert this line, devtools::document() thinks that the file is new and overwrites it.

Using a static (prebuilt) PDF vignette in R package

What is the proper way, to include a static PDF file as a "vignette" in a CRAN package as of R 3.0?
The trick described in this document of using an empty stub Rnw does not seem to work in R 3.0. The document suggests that there is now a better way based on \VignetteEngine{} but it's not quite clear how this works for static PDF files.
With R.rsp (>= 1.19.0) you can include a static PDF 'vignettes/main.pdf' by adding a tiny 'vignettes/main.pdf.asis' text file that contains:
%\VignetteIndexEntry{My amazing package}
%\VignetteEngine{R.rsp::asis}
and make sure to have:
Suggests: R.rsp
VignetteBuilder: R.rsp
in your package's DESCRIPTION file. This also works for static HTML vignettes. This is also explained in one of the R.rsp vignettes.
This works with a plain LaTeX trick as described in in this blog post.
I recently switched to doing this with the current R version (i.e. now 3.6.0), see this wrapper .Rnw file which contains just:
\documentclass{article}
\usepackage{pdfpages}
%\VignetteIndexEntry{Using Annoy in C++}
%\VignetteKeywords{Rcpp, Annoy, R, Cpp, Approximate Nearest Neighbours}
%\VignettePackage{RcppAnnoy}
\begin{document}
\includepdf[pages=-, fitpaper=true]{UsingAnnoyInCpp.pdf}
\end{document}
The advantage is that this uses Sweave for a completely traditional vignette build, and imposes no additional dependencies whatsover.
UPDATE 2014-06-08: For a better solution to including static PDFs and HTML files in an R package, see my other answer in this thread on how to use R.rsp (>= 0.19.0) and its R.rsp::asis vignette engine.
All you need is a <name>.Rnw file with a name matching your static <name>.pdf file, e.g.
vignettes/
static.pdf
static.Rnw
where <name>.Rnw (here static.Rnw) is a minimal valid Sweave file, e.g.
%\VignetteIndexEntry{<title to be displayed on the R vignette index page>}
\documentclass{article}
\begin{document}
\end{document}
This vignette source file (<name>.Rnw) tricks R CMD build to build it, i.e. R's tools::buildVignettes() will first Sweave <name>.Rnw into <name>.tex as usual. However, due to how buildVignettes() is designed it will detect our static <name>.pdf file as already being created by the Sweave engine and therefore it will not compile that dummy TeX file into a PDF file (which would overwrite our static file).
What is important to understand is that (i) vignettes are "build" during R CMD build, (ii) and when built they are copied over to the inst/doc/ directory (created if missing) of the built package. Also, (iii) the vignettes/ directory will not be part of the build package, i.e. <pkgname>_<version>.tar.gz file. So, make sure to look in inst/doc/.
So, to be clear here, using a dummy <name>.Rnw could be considered a hack that may break if someone decides to prevent against this strategy. However, if that happens, it is fully possible to create a non-Sweave vignette engine which sole purpose is to compile a <name>.pdf file into a ... <name>.pdf file. This is valid and possible due to the non-Sweave support added in R (>= 3.0.0). I've been considering adding such engine to the R.rsp package, e.g. \VignetteEngine{R.rsp::StaticPDF}. With that you would not even have to have that dummy Rnw file - only the PDF file.
Hope this helps

Resources