Mask output of `The following objects are masked from....:` after calling attach() function
You use attach
without detach
- every time you do it new call to attach masks objects attached before (they contain the same names). Either use detach
or do not use attach
at all.
Nice discussion and tips are here.
If you look at the down arrow in environment tab. The attached file can appear multiple times. You may need to highlight and run detach(filename)
several times until all cases are gone then attach(newfilename)
should have no output message.
It may be "better" to not use attach
at all. On the plus side, you can save some typing if you use attach
. Let's say your dataset is called mydata
and you have variables called v1
, v2
, and v3
. If you don't attach mydata
, then you will type mean(mydata$v1)
to get the mean of v1
. If you do attach mydata
, then you will type mean(v1)
to get the mean of v1
. But, if you don't detach the mydata
dataset (every time), you'll get the message about the objects being masked going forward.
Solution 1 (assuming you want to attach):
- Use
detach
every time. - See Dan Tarr's response if you already have the data attached (and it may be in the global environment several times). Then, in the future, use detach every time.
Solution 2
Don't use attach
. Instead, include the dataset name every time you refer to a variable. The form is mydata$v1
(name of data set, dollar sign, name of variable).
As for me, I used solution 1 a lot in the past, but I've moved to solution 2. It's a bit more typing in the beginning, but if you are going to use the code multiple times, it just seems cleaner.