Package development: Directory for non-C code/Scripts in `src/`

The src/ directory in a package is according to http://r-pkg.had.co.nz/ the place where source code other than *.R files should go to.

My problem is that, if I have a file inside this folder, devtools::build() tries to compile this file as if it would be a *.c file.

Is there a way to have files in scripting languages like Perl (*.pl) or Shell (*.sh) inside this directory without them being compiled?

For perl and shell scripts I would actually recommend you put them in exec/. from Writing R Extensions

Subdirectory exec could contain additional executable scripts the package needs, typically scripts for interpreters such as the shell, Perl, or Tcl. NB: only files (and not directories) under exec are installed (and those with names starting with a dot are ignored), and they are all marked as executable (mode 755, moderated by ‘umask’) on POSIX platforms. Note too that this is not suitable for executable programs since some platforms (including Windows) support multiple architectures using the same installed package directory.

The main benefit to inst/perl as suggested above is that the scripts in exec are marked as executable automatically when the package is installed.

1 Like

Thanks a lot for your answer. With your hints, I could also find a helpful post on stackoverflow https://stackoverflow.com/questions/26104709/is-there-any-special-functionality-in-r-package-exec-or-tools-directories with some comments by Hadley Wickham.

Mara pointed out to me that the inst/ directory is also a suitable place where scripts in other languages could go into subdirectories like, for example, inst/perl (see http://r-pkgs.had.co.nz/inst.html#inst-other-langs).

Restoring this for posterity:

See Jim's answer This content in this answer would mean the scripts would not be marked as executable upon installation.

For supplementary scripts, you should use the inst/ folder. From the Installed files - Other languages section of Packages:

The convention is to put scripts of this nature into a subdirectory of inst/, inst/python, inst/perl, inst/ruby etc. If these scripts are essential to your package, make sure you also add the appropriate programming language to the SystemRequirements field in the DESCRIPTION. (This field is for human reading so don’t worry about exactly how you specify it.)

If you have other languages you want compiled, you can use a custom makefile. See the Compiling in subdirectories section in Writing R Extensions.

1 Like

Thanks again. This is very helpful.