Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R package: use a custom file/directories structure in pkg/R and pkg/src folders

I'm writing a R package which begins to grow in size, and so would really appreciate to use a custom structure in folders pkg/R/ and (especially) in pkg/src/.

For example, let's say I have two families of algorithms of some type A, and some functions of type B, and a main entry point. Ideally R/ or src/ folders would be organized as follow:

  • typeA/
    • algorithms1/
      • algo11.ext
      • ...
    • algorithms2/
      • algo21.ext
      • ...
  • typeB/
    • function1.ext
    • ...
  • main.ext

with "ext" in {R,cpp,c,f,...}, and potentially two files having the same name.

Is it possible ? If yes, how can I do that ?

Thanks in advance !


[2012-12-31] EDIT: an idea would be to write a few scripts - maybe inside another R package - to (un)flatten a structured package for tests or diffusion. But there is probably a better solution, so I will wait a bit.

like image 582
BenjaminAuder Avatar asked Dec 20 '12 19:12

BenjaminAuder


People also ask

What does. Rbuildignore do?

Rbuildignore file. It controls which files from the source package make it into the downstream forms. Each line of . Rbuildignore is a Perl-compatible regular expression that is matched, without regard to case, against the path to each file in the source package 1.

What is r source package?

A source package is just a directory of files with a specific structure. It includes particular components, such as a DESCRIPTION file, an R/ directory containing . R files, and so on. Most of the remaining chapters in this book are dedicated to detailing these components.

What is the inst folder in R package?

When making an R package the inst folder is for files/folders that should be copied unmodified into the installed R package folder.


1 Answers

As the 'Writing R extensions' manual indicates here, a Makevars file under pkg/src allows to have nested subfolders for C/C++/Fortran code. (See e.g. RSiena package).

However, I didn't find anything concerning a custom structure in pkg/R. So I wrote a little package (usable, although needing improvements) which accomplish the following tasks:

  • Load/Unload a package having (potentially) nested folders under pkg/R
  • Launch R and/or C unit tests on it [basic framework, to be replaced (e.g. RUnit and check)]
  • Export the package to be CRAN-compatible (flatten R code, generate Makevars file)

I will link it here if it reaches a publishable state. (For the moment I could send it by email).

like image 142
BenjaminAuder Avatar answered Oct 25 '22 07:10

BenjaminAuder