Forums | OpenR

OpenR: R & Statistics /
Strategy to deal with "The following object is masked from XXX:" when using attach()


Luning Yang's profile picture
Posts: 6

16 March 2022, 10:43 PM

Dear classmates and Professor Zhao:

          When I take a shortcut method to name the objects using attach(), one problem bothering me is that several object names are overlapped among different data tables. For example, the 'location' in AIR QUALITY is actually different from the 'location' in HEAVY METAL. Frequent use function attach() may cause the problem of "The following object is masked from XXX.". I try to use the function detach() to get rid of the objects of the search path, but it seems that it does not work well enough. Do we have some alternatives?

      Another question about this function attach () is that when the object name in the data table is conflicted with the inner object of R,  even a warning message appears, it is amazing that the following calling of this object works well and accurately.  Can anyone explain it to me and help me? Thank you so much~ 

屏幕截图 2022-03-16 224203.png

屏幕截图 2022-03-16 223231.png

Jiayi Li's profile picture
Posts: 5

16 March 2022, 11:35 PM

My solution to your first problem is to run detach() a few more times until Error in detach() : the 'name' parameter is wrong. So you can use attch() again

Peng Zhao's profile picture
Posts: 128

17 March 2022, 9:49 AM

I am not a fan of the attach() function. It brings you convenience and trouble. My solution is simply not using it. But it is totally up to you.

An alternative is the with() function. For example:

with(airquality, 
     {
       plot(Ozone, Solar.R)
     }
)

You can use the column names within the with() function, surrounded by "{}". It is not valid outside the "{}". Therefore, there is no conflict if there is an object with the same name as Ozone or Solar.R outside the with() function.

Edits to this post:
3 results