7
$\begingroup$

I'm currently creating an R package, and my scripts require before any analysis is done that 1-2 bed files be loaded. Normally, I would run the scripts with the following:

library(data.table)
session_bed = read.table("/path/name/to/bedfile.bed")

and then refer to session_bed 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.

(1) Normally, how are bed files distributed in R packages? Are these gzipped? Where are they placed?

According to http://r-pkgs.had.co.nz/data.html, all .bed files should be inst/extdata I guess. However, it's not clear to me how to "link" to this data within the R package.

How have other packages dealt with this? (Is there a size limit?)

(2) In this case, should the function loading the bed file be executed about loading the R library, library(package_name)? Is there more appropriate option?

$\endgroup$

2 Answers 2

7
$\begingroup$

You can store it in data/ subfolder. If one of your functions need this bed file, you can include importing it in your function.

Here are some examples how to get the data from data/ subfolder.

There are probably more ways to do this, this is just one way.

$\endgroup$
0
6
$\begingroup$

As benn said you can store them in data/ subfolder of your package. There is no size limit (AFAIK) but if you plan to publish your package in some repositories they might have limits or other restrictions. Bioconductor requires to divide the data required for a software package at certain threshold, but for small amount of data it is fine.

You can find them via system.file like: read.csv(system.file("data/mydata.csv", package = "mypackage")). Of course your bed files will need the apropiate function to load them.

You can load when your library is called by modifying the local variable, or using .First (I am not so sure of the last one), but this pollutes the environment and sometimes if preferably to use data function. You might need to convert your files to .Rdata file.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.