After you’ve been using R for a little bit, you start to notice people talking about their .Rprofile as if it’s some mythical being. Nothing magical about it, but it can be a big time-saver if you find yourself typing things like, “summary()” or, the ever-hated, “stringasfactors=FALSE” ad nauseam.
Where is my .Rprofile?
The simple answer is, if you don’t know, then you probably don’t have one. R-Studio doesn’t include one unless you tell it to. In Mac and Linux the .Rprofile is usually a hidden file in your user’s home directory. In Windows the most common place is C:Program FilesRRx.xetc.
Check to see if I have an .Rprofile
Before creating a new profile, fire up R and check to see if you have an existing .Rprofile lying around. Like I said, it’s usually a hidden file.
How to create an .Rprofile
Assuming you don’t already have one, these files are easy to create. Open a text editor and name your blank file .Rprofile with no trailing extension and place it in the appropriate directory. After populating the file, you’ll have to restart R for the settings to take affect.
Below is a snapshot of mine. Of coarse, you can make this as simple or as complex as you like.
## Print this on start so I know it's loaded. cat("Loading custom .Rprofile") ## A little gem from Hadley Wickam that will set your CRAN mirror and automatically load devtools in interactive sessions. .First
Limitations and gotchas
The major disadvantage to all this is code portability. For example, if you set your .Rprofile to load `dplyr` on every session, when someone else tries to run your code, it won’t work. For this reason, I’m a little picky about my settings, opting for functions that will only be used in interactive sessions.