Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of objects being masked by the global environment

Tags:

r

When I load my package into the global environment, I get the following message

> library(saber)  Attaching package: ‘saber’  The following objects are masked _by_ ‘.GlobalEnv’:      load.schedule, teamStats 

I don't know what that means, nor whether I should be concerned about it.

Why is this message being delivered, and what does it mean?

like image 811
Rich Scriven Avatar asked Jul 11 '14 22:07

Rich Scriven


2 Answers

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,

  1. don't create objects with those names in your global environment
  2. rename the objects in your package to something that's less likely to create a conflict, or rethink your decision to export them, or
  3. 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.

like image 71
joran Avatar answered Sep 17 '22 04:09

joran


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.

like image 41
JRT Avatar answered Sep 20 '22 04:09

JRT