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 Files\R\Rx.x\etc.
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.
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.
To leave a comment for the author, please follow the link and comment on their blog: Data Science Riot!.