Meaning of objects being masked by the global environment
It means that you have objects (functions, usually) present in your global environment with the same name as (exported) things in your package. Type search()
to see the order in which R resolves names.
The solution is to either,
- don't create objects with those names in your global environment
- rename the objects in your package to something that's less likely to create a conflict, or rethink your decision to export them, or
- remember that you will always have to refer to those objects as
saber::teamStats
.
Probably (2) is best, unless the circumstances that led to the message are truly unusual.
The answers above give the low-level causes.
I just thought it would be useful to point out I got that message when I had a project open in RStudio and I loaded the "same" library of that project.
With the explanations above its obvious doing this creates some kind of conflict.
This means that you have objects named load.schedule
, teamStats
in your workspace as well as in the library you are loading. It is warning you that when you call load.schedule
it will use the one in your workspace (since it is first in the search path) rather than the one you are attaching. Try for example
ddply <- function(x) x + 1
library(plyr)
# Attaching package: ‘plyr’
#
# The following object is masked _by_ ‘.GlobalEnv’:
#
# ddply
ddply(3) # the one we just defined is used, as global env is first in the search path
#[1] 4
There's a third implied question that I don't think has been fully answered for this particular case. How to fix it in the situation where an earlier version of your own function is stuck in the global environment and masking new versions you're trying to test?
Renaming your function with every rev is not practical in this situation. I had the same situation and found deleting the .Rdata file in the working directory before restarting R solved the problem.
This has happened to me only twice over hundreds of time assembling my packages. I'm still not sure how the functions are occasionally getting stuck in global.