First let me explain that I come from the Python world, where I can do what I want like this in the shell:
$ export PYTHONPATH=~/myroot
$ mkdir -p ~/myroot/mypkg
$ touch ~/myroot/mypkg/__init__.py # this is the one bit of "magic" for Python
$ echo 'hello = "world"' > ~/myroot/mypkg/mymodule.py
Then in Python:
>>> import mypkg.mymodule
>>> mypkg.mymodule.hello
'world'
What I did there was to create a package which is easily extended by other users. I can check in ~/myroot/mypkg to source control and other users can later add modules to it using just a text editor. Now I want to do the equivalent thing in R. Here's what I have so far:
$ export R_LIBS=~/myR # already this is bad: it makes install.packages() put things here!
$ mkdir -p ~/myR
$ echo 'hello = "world"' > /tmp/mycode.R
Now in R:
> package.skeleton(name="mypkg", code_files="/tmp/mycode.R")
Now back to the shell:
$ R CMD build mypkg
$ R CMD INSTALL mypkg
Now back to R:
> library(mypkg)
> hello
"world"
So that works. But now how do my colleagues add new modules to this package? I want them to be able to just go in and add a new R file, but it seems like we then have to redo the entire package building process, which is tedious. And it seems like we will then end up checking in many generated files. But most importantly, where did the code go? Once I did CMD INSTALL
, R knew what my code was, but it did not put the literal text (from mycode.R
) anywhere under $R_LIBS
(did it "compile" the code? I'm not sure).
Previously we would just source()
our "modules" but this is not very good because it reloads the code every time, so indirect (transitive) dependencies end up reloading stuff that is already loaded.
My question is, how do people manage simple, in-house, collaboratively edited, source-controlled, non-binary, non-compiled, shared code in R?
I'm using R 3.1.1 on Linux. If the solution works on Windows too that would be nice.