pkgdown and R Markdown templates - r

For a package containing multiple R Markdown templates, is it possible to include the rendered versions of these templates (skeleton.Rmd) as vignettes / articles in the package documentation website (set up using pkgdown). I'd like to get a a nice overview of all the templates which are available in the package.
I want to avoid creating new vignettes which copy/paste the code from the R Markdown templates to vignettes/articles. Ideally, I'd just like to link them to the templates (skeleton.Rmd in the inst/rmarkdown/templates directory).
Any suggestions on how I can achieve this?
Thanks!
Originally posted on 2020-08-19 on Posit Community but without response.

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

How to embed tweets in R markdown documents being knit to HTML?

It is fairly easy to embed tweets into blog post using the blogdown R package and Hugo shortcodes as described at https://bookdown.org/yihui/blogdown/content.html.
I would like to embed tweets in an R markdown document that is being knit to a standalone HTML document. What is the best way to do this? It looks like Twitter provides an Embed Tweet functionality that I can use interactively to get HTML to embed a tweet, but I need to do this programmatically, given a tweet id.
For people who don't want to go to twitter, the thread includes recommendations for two packages. twittrmd and twitterwidget. I was able to get twittrmd to work as follows:
Install packages
This was the hard part, because the CRAN webshot2 repo wasn't compatible with my R environment.
devtools::install_github("gadenbuie/tweetrmd")
# necessary if your output type is not html (as far as I can tell)
devtools::install_github("rstudio/webshot2")
# this is a webshot2 requirement
install.packages("magick")
Use packages
With these packages you can capture a screenshot by
library(twittrmd)
include_tweet("https://twitter.com/nomadj1s/status/1294390352904966151")
If your output type is not html, tweetrmd will rendered as a png or pdf. In any case, I think you can only see the tweet upon knitting.
More info is available on the github, including helper functions to build twitter urls from a username and tweet_id and ideas about how to use memoise to keep a copy of the tweet in the case that it's removed from twitter.

Duplicate package documentation in RStudio

I've started creating a package through RStudio. When I start a new package (New Project -> New Directory -> R Package) the documentation for the base package is duplicated, with one help page titled 'packagename-package' and the other called 'packagename' (see image below).
Although there are two help pages visible, there is only one .Rd file in the man/ folder ('packagename-package.Rd'). When I edit this .Rd file, the information changes in both the duplicate help pages. Is this a known issue when building packages in RStudio, and is there a way to get rid of one of these duplicates?
Thanks for your help.

Linking to documentation page without function in R using roxygen2

I am wondering if there is a possibility, during writing a package in R, to link to the documentation page in R that has no functions included but has only package-info?
For example \link[stats]{stats-package.R}?
One of the possibillities is \link[stats]{stats-package} without .R extansion (but it will link to stats-package page). If you just want to link the package use \pkg{package} e.g. \pkg{stats}. For more info try Writing R Extensions

R -- Vignettes that are not made by Sweave possible?

Can I include some PDF in the pkg/doc folder so that the vignette function works, but no corresponding Rnw, Rtex, etc exists?
I am thinking of slides or documents containing markdown text weaved with R chunks, which have a different build process and hence different file extensions.
The writing R extensions guide suggests that it should be possible to include documents which can not be build at installation time, but the vignette function seems to look for files with special extensions (Rnw, Rtex, etc) and also for a file called vignette.rds.
Any hints are appreciated.
I asked about this several years ago, and while Fritz Leisch is amenable to the idea, he hasn't had the time to implement it.
(Cross-posted from a response I just left on R-help:)
As a workaround, you could include your own xvignette function in your package: see below.
It won't show you indices, but it will pick up any appropriately named file that you include in the inst/doc directory of your
package ...
xvignette <- function(vname,pkg,ext="pdf") {
vname <- paste(vname,ext,sep=".")
fn <- system.file("doc",vname,package=pkg)
if (nchar(fn)==0) stop("file not found")
utils:::print.vignette(list(pdf=fn))
invisible(fn)
}
You'll have to somehow alert your package users to the fact that this alternative documentation exists -- perhaps in the help file for the package itself.
You might fill in the default value of pkg above with your package name to make it easier on the user: I thought about using some variant of getPackageName(environment(xvignette)) to do it automatically, but that seems too complicated ...
Brian Ripley also mentioned in his response to the question that:
At present vignette() means Sweave documents, as only they have
metadata like titles. This is planned to be changed soon.
... but I don't know what "soon" means (it will be about 6 months until 2.14.0 comes out, I think)
edit: http://article.gmane.org/gmane.comp.lang.r.devel/28449 details another workaround (creating a dummy vignette that incorporates the existing PDF file)
edit 2: And
here's what Yihui Xie has to say about including knitr-based vignettes in packages (essentially another "dummy vignette" strategy)
vignette about non-Sweave vignettes from the R.rsp package
This is supported natively as of R 3.0.0, see http://yihui.name/knitr/demo/vignette/.
Instructions to use knitr as vignette engine boil down to:
add %\VignetteEngine{knitr::knitr} to the Rnw source document (note you still need %\VignetteIndexEntry{} as before)
specify VignetteBuilder: knitr in the package DESCRIPTION file
add Suggests: knitr in DESCRIPTION if knitr is needed only for vignettes
See also the official R documentation on that topic.

Resources