Trouble loading R package data - r

I've developed a R package but for some reason the dataset that goes with the package is not being loaded properly when the package is Roxygenised and installed. I have a .R script in the R folder of the package that looks like this
#' Score Card
#' #docType data
#' #name scoreCard
#' #aliases scoreCard
#' #format An object of class \code{data.frame} with 119 rows and 3 columns.
#' \describe{
#' \item{Category}{The Category for which an observation is made}
#' \item{Observation}{The possible responses given for each category}
#' \item{Score}{The score allocated against a response for each category}
#' }
#' #source Internal
#' #usage scoreCard
#' #keywords datasets
NULL
This creates an .Rmd file for the dataset when Roxygenise is called but when I try to call the data set using packageName::scoreCard it states 'scoreCard' is not an exported object from 'namespace:packageName'. Can anyone spot what I might have done wrong in the above script or any other ideas of what might be going wrong, I'm at a bit of a loss? (The data set is stored in the data folder of the package as per normal.) Afraid I can't share the data or package sorry.

Right I didn't realise I needed LazyData: true in my description file. Should have read this more carefully: http://r-pkgs.had.co.nz/data.html

Related

Is a package's help index page customizable?

The help() function allows us to see an index with a list of all functions within a package:
help(package=stats)
If the package is very large, the help page will be automatically broken down alphabetically, with links to each section by initial letter (as in the case of stats). Smaller packages will have all the functions together in alphabetical order.
Is this index page customizable?
I'm using roxygen2, and would love to be able to group functions by their #family.
See section 10.6 of R Packages :
You can use roxygen to provide a help page for your package as a whole.
you need to document NULL, and then manually label it with #docType package and #name . This is also an excellent place to use the #section tag to divide up page into useful categories.
Just create an mypackage.R file with the above Roxygen tags applied to NULL:
#' Mypackage: A package I created
#'
#' MyPackage has different families of functions described below
#'
#' #section Some functions:
#' * [mysum()]
#' * [myprod()]
#'
#' #section Other functions:
#' * [other()]
#' * [foo()]
#'
#' #docType package
#' #name mypackage
NULL
The brackets [] allow to create links to the functions of the package.

R devtools: package documentation on first page of the manual

How do I make devtools::build_manual put package documentation on the first page of the manual?
#' flowNet: Mapping the Topology of Single Cell Data
#'
#' Some text...
#'
#' #section Some more text...
#'
#' #docType package
#' #name flowNet
NULL
#> NULL
.datatable.aware <- TRUE
Output:
I do not think you can, and you have your tools crossed. devtools does not influence how base R collates all Rd entries into a pdf.
But I just took one guess at an older package (xts) by a friend and indeed, it has a first entry ending in "-package":
So just add an entry flowNew-package (via roxygen2) and you should be good.
Here is another example from a package of mine:

R calling a dataset in the package itself

I have created a package containing a dataset called mydata.
I want to use my dataset in my functions but I dont know how to call it.
when i use data("mydata") to call my dataset and avoid warning messages I have another message during the building process
See section ‘Good practice’ in ‘?data’.
#imporFrom mypackage mydata doesn't work either. What's the best way to call a dataset in the package itself?
Use package_name::mydata, example in car package car::Angell.
Dataset is in a data folder with for example mydata.rda inside.
To add help, create a data.R file in R folder.
Personnaly I put inside :
# 1. mydata ----
#' Here is a long title
#'
#' Description of the dataset : length, columns
#'
#' #format one object of class XXX
#'
#' #source where it comes from
#' #name mydata
NULL

Can't access dataset documentation in R

I have created a package using devtools and roxygen2, which works perfectly fine. Now I want to include two data frames termed mydata1 and mydata2 into the package.
I have saved the data frames in mypackage/data as mydata1.rda and mydata2.rda using devtools::use_data(mydata1, mydata2)
Then I created a mydata1.R and mydata2.R files in mypackage, which contains the description as follows:
#' My temperature data
#'
#' A dataset containing the temperature
#'
#' #format A data frame with 153 rows and 1 variable:
#' \describe{
#' \item{temperature}{relative air temperature in degree Celsius}
#' }
"mydata1"
However, after I install and restart in the package build mode, I cannot access the description via help(mydata1). I can access the data via mypackage::mydata1 though.
What am I doing wrong? It might be a stupid mistake, however, I could not find a solution so far. Thank you very much in advance.
Ok I found the solution, I just needed to save the description files in mypackage/R and not in mypackage.

Cannot find documented data

I'm creating a new package and documenting lookup tables stored in the data/ folder using an R script as per the instructions here http://r-pkgs.had.co.nz/data.html. I have two .rda tables, one for looking up the product based on a product code and another looking up the category based on the category code. (e.g. data/productlookup.rda)
Here's an except of my documented data which is stored in the R/ folder of the package.
#' ProductDecodes: Extract info from Product Codes
#'
#' This package contains functions for the extraction of information
#' from Product codes.
#'
#' #docType package
#' #name productDecoding
NULL
#' Product lookup
#'
#' #source internal
"productlookup"
#' Category lookup
#'
#' #source internal
"categorylookup"
However, when I come to roxygenise the package I get an error stating the .rda tables cannot be found.
Error in get(name, envir = env) : object 'productlookup' not found
The error doesn't occur when the tables are loaded into the global environment first. What I want to know is whether it is possible to roxygenise the package without having to load the .rda into the global environment first? I don't understand why roxygenise needs the lookup tables to be in the global environment in order to find them. Any help/explanation of why this error is occurring would be appreciated.
This is what I usually do and I've just tested successfully with roxygen2 5.0.1:
#' Product lookup
#'
#' #format A data.frame with 200 rows and 2 variables:
#' \itemize{
#' \item prod: product name
#' \item val: product value in US$
#' }
#'
#' #source internal
#' #name productlookup
NULL
Of course, the resulting help page needs more information.

Resources