Data inside a function (package creation)
r
Solution
One can just place the data set as a .rda file in the R folder as described by Hadley here: http://r-pkgs.had.co.nz/data.html#data-sysdata
Matthew Jockers uses this approach in the syuzhet package for data sets including the `bing` data set as seen at ~line 452 here: https://github.com/mjockers/syuzhet/blob/master/R/syuzhet.R
`bing` is not available to the user but is to the package as demonstrated by: `syuzhet:::bing`
Essentially, the command `devtools::use_data(..., internal = TRUE)` will set everything up in the way it's needed.
Problem
If I need to use a data set inside a function (as a lookup table) inside of a package I'm creating do I need to explicitly load the data set inside of the function? The function and the data set are both part of my package. Is this the correct way to use that data set inside the function: ``` foo <- function(x){ x <- dataset_in_question } ``` or is this better: ``` foo <- function(x){ x <- data(dataset_in_question) } ``` or is there some approach I'm not thinking of that's correct?