Collaborator-specific commands in R

When you're sharing an R script with someone, sometimes you both need to run commands that only make sense for you and on your system. How do you manage it?

One way is to have your own system-specific file that you run before the shared script. But this doesn't really solve the problem... you still want that script version controlled so that it is safe and your work is reproducible.

Fortunately, you can set up environment variables to help handle it.

Add the following line


to the .Renviron file. This is located at:

  • ~/.Renviron on Linux
  • C:\Program Files\R\rw1051\etc\ (example) on Windows (I haven't tested this)
  • ~/.Renviron on Mac (I haven't tested this either)

Begin your shared R script with stanza:

} else if(computer_id=="collaborator_name") {

Modifying the file would work as well, but then all users on your system would inherit the R_COMPUTER_ID variable and you would need sudo access.