Loading dplyr via Rprofile.site in Rstudio
Since I found it, I am using dplyr religiously. Since I use it so much, I tried to put library(dplyr)
into my .First () function in Rprofile.
This loads dplyr, but when I start Rstudio some of the dplyr functions are masked. For example, when I try to do:
foo <- mtcars %>% filter( cyl == 4 )
I am getting the following error:
Error in filter(mtcars, cyl == 4) : object 'cyl' not found
A bit of troubleshooting found out that if I run the library (dplyr) again in the console, the problem is fixed - obviously one / some of the dplyr functions are masked by something further down the search path (or up, depending on how you're looking at it.
When I look at my search path () I see that a lot of other packages are being downloaded after dplyr, which is not at all what I want (I would prefer dplyr to be the last loaded, or at least almost the last):
[1] ".GlobalEnv" "tools:rstudio" "package:stats" "package:graphics" "package:grDevices" "package:utils"
[7] "package:datasets" "package:xlsx" "package:xlsxjars" "package:rJava" "package:dplyr" "package:methods"
[13] "Autoloads" "package:base"
I am on Windows 7 using RStudio v.0.98.1028. Since I don't really understand how Windows + RStudio handles the home directory, I'm editing Rprofile in C:/Program Files/R/R-3.1.1/etc/
. Any suggestions?
source to share
In starting order for R (see ?Startup
), .First()
called before .First.sys()
, which loads other packages. This is the package stats
that overwrites filter
.
.First.sys()
uses options("defaultPackages")
to determine what to load, so I suggest you edit that in your function .First()
with
options(defaultPackages=c(getOption("defaultPackages"),"dplyr"))
source to share