Some R packages (e.g., ggplot2, dplyr,devtools etc.) have alphabetically entitled sections in their help/documentation and a bar of links to those sections (indicated by red arrows in picture below). Other packages (e.g., RcmdrMisc) don't have.
How can I add these elements to may R package's help?
I use roxygen2 for documentation.
In the Writing R Extensions file (included with every copy of R from CRAN) is a small section regarding the INDEX file:
1.1.4 The INDEX file
The optional file INDEX contains a line for each sufficiently interesting object in the package, giving its name and a description (functions such as print methods not usually called explicitly might not be included). Normally this file is missing and the corresponding information is automatically generated from the documentation sources (using tools::Rdindex()) when installing from source.
When packages have an index file, the HTML code is in the html folder.
The help index page is automatically generated by R when you install a package. But note that the alphabetical index is only generated when there are more than 100 items on the index page. There is currently no way to change that behavior. I found that in the code for installing packages
As #iRTFM and #MrFlick say, you can't affect the index displayed by R. However, if you use the pkgdown package to make a package web page, you have full control over the main index for the help pages. For example, see
https://ggplot2.tidyverse.org/reference/index.html
The description about how that index was specified is given in the help page ?pkgdown::build_reference, which is displayed here:
https://pkgdown.r-lib.org/reference/build_reference.html
Related
Following advice about NAMESPACE and External Data formatting/setup, I have:
A. My data files in mypackage/data/datafilename.RData
B. The data script as mypackage/R/data.R with data files individually named and described within that one file, having just changed "itemize" to "describe" and changing the format of those item lines:
C. I've document()-ed this, commit-pushed to github, and install_github reinstalled locally.
Help for the data files works:
But I can't access those data, whereas I can access data in other packages using the same method:
Can anyone think why this would be? NAMESPACE doesn't include these as exports:
But it's autogenerated by document() so that's arguably out of my control. By comparison, mapplots' NAMESPACE has exportPattern(".")
Environment for the package also doesn't include them, but I don't know if this is expected or not, based on lazy loading (which is true):
Any ideas welcome. I've tried data(gbm.auto:grids) with 1, 2 & 3 colons, to no avail. Based on the answer to this related question (also by me), I get the suspicion that there might be some issue whereby only the last named object in data.R is important/accessible?
usethis has been created since I've been updating this package and has use_data and create_package but I'm reluctant to try these out since ostensibly everything in my package should already be in order and I don't want to make things worse.
Thanks in advance. Reprex would be
library(devtools)
install_github("SimonDedman/gbm.auto")
Edit: to add to this, the datasets available in the installed package are a combo of the full list, some individual, some named in datalist:
Which contrasts against what's in the working folder and github:
As far as I can see, all the data files are the same format, e.g. when doubleclicked in file explorer they open in RStudio with the right name and same format. gbm.auto/R/data.R file is here. Per the last image, the three data files listed in datalist can be loaded in R with library(gbm.auto) data(Juveniles), but the other three data files can't. If I delete/rename the existing datalist from /data and generate a new one with add_datalist(pkgname = getwd()), a new file is generated but again it only lists those 3 files, not all 6.
Ugh, goddamn it. Found the issue. The 3 'bad' files had "Rdata" extensions while the 3 good ones had "RData" extensions. Lower case vs capital D. How unbelievably annoying.
Data files in data must have .RData extensions, not .Rdata
Bug filed here.
I am currently developing an R package and want it to be as clean as possible, so I try to resolve all WARNINGs and NOTEs displayed by devtools::check().
One of these notes is related to some code I use for generating sample data to go with the package:
checking top-level files ... NOTE
Non-standard file/directory found at top level:
'generate_sample_data.R'
It's an R script currently placed in the package root directory and not meant to be distributed with the package (because it doesn't really seem useful to include)
So here's my question:
Where should I put such a file or how do I tell R to leave it be?
Is .Rbuildignore the right way to go?
Currently devtools::build() puts the R script in the final package, so I shouldn't just ignore the NOTE.
As suggested in http://r-pkgs.had.co.nz/data.html, it makes sense to use ./data-raw/ for scripts/functions that are necessary for creating/updating data but not something you need in the package itself. After adding ./data-raw/ to ./.Rbuildignore, the package generation should ignore anything within that directory. (And, as you commented, there is a helper-function devtools::use_data_raw().)
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
I get this warning
Non-standard file/directory found at top level:
‘data-raw’
when building my package, even there is the recommendation of creating this folder to create package data http://r-pkgs.had.co.nz/data.html#data-sysdata
Any comments on that or do I need a specific setting to get rid of this message.
When used, data-raw should be added to .Rbuildignore. As explained in the Data section of Hadley's R-Packages book (also linked in the question)
Often, the data you include in data/ is a cleaned up version of raw data you’ve gathered from elsewhere. I highly recommend taking the time to include the code used to do this in the source version of your package. This will make it easy for you to update or reproduce your version of the data. I suggest that you put this code in data-raw/. You don’t need it in the bundled version of your package, so also add it to .Rbuildignore. Do all this in one step with:
usethis::use_data_raw()
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.