Your Rprofile is a script that R executes every time you launch an R session. You can use it to automatically load packages, set your working directory, set options, define useful functions, and set up database connections, and run any other code you want every time you start R.
If you’re using R in Linux, it’s a hidden file in your home directory called ~/.Rprofile, and if you’re on Windows, it’s usually in the program files directory: C:\Program Files\R\R-2.12.2\library\base\R\Rprofile. I sync my Rprofile across several machines and operating systems by creating a separate script called called syncprofile.R and storing this in my Dropbox. Then, on each machine, I edit the real Rprofile to source the syncprofile.R script that resides in my Dropbox.
One of the disadvantages of doing this, however, is that all the functions you define and variables you create are sourced into the global environment (.GlobalEnv). This can clutter your workspace, and if you want to start clean using rm(list=ls(all=TRUE)), you’ll have to re-source your syncprofile.R script every time.
It’s easy to get around this problem. Rather than simply appending source(/path/to/dropbox/syncprofile.R) to the end of your actual Rprofile, first create a new environment, source that script into that new environment, and attach that new environment. So you’ll add this to the end of your real Rprofile on each machine/installation:
All the functions and variables you’ve defined are now available but they no longer clutter up the global environment.
If you have code that you only want to run on specific machines, you can still put that into each installation’s Rprofile rather than the syncprofile.R script that you sync using Dropbox. Here’s what my syncprofile.R script looks like – feel free to take whatever looks useful to you.