Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including Script Files in an R Extension Package

Tags:

package

r

I'm creating an R package and I need it to include a couple of non R script files which get called by one of my functions. I need these script files to be distributed with the package, naturally. So that leaves me with two questions:

  1. a) In which directory of the package tree should I place these files? b) Is that location mandatory or just convention?
  2. Do I need to change any other settings or configurations or will they just get copied to the directory mentioned in #1 and then I can figure out the path using system.file()?

I've tried to find the answer in the Writing R Extensions document, but it didn't jump out at me. And, of course, I didn't read the whole thing. Am I being too honest here?

like image 529
JD Long Avatar asked Jul 27 '10 20:07

JD Long


People also ask

What is the extension of a script file in R?

An R file is a script written in the R programming language. These files end with an . R extension.

How do you open a .R file in RStudio?

Click on the Open an existing file icon in the RStudio toolbar. A Choose file dialog will open. Select the R script you want to open [this is one place where the . R file extension comes in handy] and click the Open button.

How do I open a .R file?

The R and RStudio programs are typically used to open R files since they provide helpful IDE tools. You can also use a plain text editor to view the contents of an R script.

How do I create a .R file?

There are two ways to create an R file in R studio: You can click on the File tab, from there when you click it will give a drop-down menu, where you can select the new file and then R script, so that, you will get a new file open.


1 Answers

I think you want either exec/ at the top-level (even though that is labeled 'still experimental, or subdirectory of inst as everything in inst/ gets copied verbatim into the package.

A quick example from the packages I have expanded in source is gdata which has inst/perl, inst/xls and inst/bin. These you could then call from R itself by computing the path of the installed package using system.file().

like image 114
Dirk Eddelbuettel Avatar answered Oct 16 '22 05:10

Dirk Eddelbuettel