22

I wonder if there is a way to mask the long list output of The following objects are masked from XXX(position 11): every time I call attach() function?

1
  • 3
    Just don't use attach. please. Apr 10, 2016 at 21:29

5 Answers 5

32

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.

1
  • 1
    Even after detaching, and then attaching, I got the same warning message. Any alternative suggestions this.? Jun 17, 2017 at 4:28
8

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.

attached files under environment tab

5

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):

  1. Use detach every time.
  2. 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.

1
  • I am having same problem. I am not using attach but my column contains negative value like -19.03. How to work with this situation?
    – user1413
    Nov 18, 2022 at 16:38
0

keep using detach(dataframe) multiple times till it returns "object not found" answer and then the masking response will go away

1
-1

You actually don't need to use the attach at all. I had the same problem and it was resolved by removing the attach statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.