5

I use R 3.5.1 in RGui/RStudio and a '.Rprofile' file in my user's home directory with a single entry to preload the package 'tidyverse': library(tidyverse)

When wanting to use the filter() function of package 'dplyr' it gets masked by the filter() function of package 'stats', that has been loaded as a default package AFTER sourcing '.Rprofile' in the R startup process.

This behaviour seems to be contradictory to what ?Startup tells us: "Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned."

Can someone tell me please, why the default packages like 'stats' are beeing loaded despite of using a user profile file? Thanks a lot!

Gregor Kvas
  • 151
  • 1
  • 7
  • Couple of questions: 1. When you use dplyr filter() does it work? 2. Is your .Rprofile in the same folder as the other libraries (e.g. stats)?. It's odd because I've always been able to use dplyr filter(), even when the stats package is loaded. – Pryore Dec 05 '18 at 09:39
  • Sorry for the late reply! Ad1: {dplyr} filter() does NOT work, when {stats} is loaded AFTER loading {dplyr} via sourcing '.Rprofile' in project folder, which is odd, because due to '.Rprofile' only {base} should be loaded by R (?Startup). Ad 2: No, my '.Rprofile' is in my project folder in Windows "Documents" folder and the library {stats} is in R folder "C:\Program Files\R\R-3.5.1\library\stats". Yes, {dplyr} filter() always works when {dplyr} is loaded AFTER {stats}. – Gregor Kvas Feb 20 '19 at 12:51

2 Answers2

2

My question has already been answered here: R dplyr filter not masking base filter? [duplicate]

As outlined before, the documentation of ?Startup says:

Note that when the site and user profile files are sourced only the base package is loaded, so objects in other packages need to be referred to by e.g. utils::dump.frames or after explicitly loading the package concerned.

Unfortunately this can be easily misunderstood and therefore had initially led to my question. The phrase "only the base package is loaded" means, that only the base package will be loaded as the very first package in the startup process, but other default packages like stats will be loaded AFTER the packages sourced via an user .Rprofile file.

This is the reason why the filter() function of package dplyr being loaded in an user .Rprofile file during the startup process gets masked by the filter() function of the default package stats, being loaded AFTER the sourced user .Rprofile file.

Gregor Kvas
  • 151
  • 1
  • 7
0

.Rprofile runs before R loads basic libraries load package stats first

library('stats', warn.conflicts = TRUE, verbose = TRUE) 
library('dplyr', warn.conflicts = TRUE, verbose = TRUE)
s_baldur
  • 29,441
  • 4
  • 36
  • 69
Captain Tyler
  • 500
  • 7
  • 19