Releasing an R package with several large text files, when to load?

package

#1

I’m currently creating an R package, and my scripts require before any analysis is done that 3-4 text files be loaded. Normally, I would run the scripts with the following:

library(data.table)
session_data = read.table("/path/name/to/filename.txt")

and then refer to session_data throughout the analysis.

However, in order to release this as an R package, I believe that these files must be downloaded at the time on the package installation.

When do I load it and assign it to a variable, e.g. session_data? In a function? In this case, should the function loading the text file be executed about loading the R library, library(package_name)? Is there more appropriate option?


#2

This depends how large your text files are and how and where you plan to distribute the package.

http://r-pkgs.had.co.nz/data.html has a full discussion of some of the options, but you need to give more details to answer your question fully.

You should definitely not automatically download files when attaching the package.


#3

Hi @jimhester

Thank you for the reply.

I think the remaining question is, is it better to define global variables in a package via onLoad(), or re-define these variables (e.g. session_data = read.table(...)) within an individual function?


#4

Maybe this can help you
http://r-pkgs.had.co.nz/data.html#data-sysdata