6.2 C
London
Thursday, December 19, 2024
HomeRFix Common Errors in RHow to Interpret R Message: The following objects are masked

How to Interpret R Message: The following objects are masked

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

You may sometimes encounter the following message in R:

The following objects are masked from 'package:stats':

    filter, lag

This message appears when you load some package in R that contains functions that share names with functions that are already loaded from some other package in your current environment.

For example, suppose I load the dplyr package in R:

library(dplyr)

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

From the output we can observe:

1. The functions called filter and lag are masked from the R stats package.

  • If we use filter() or lag() in our R code, the filter() and lag() functions from dplyr will be used since it was the package loaded most recently that contains these functions.

2. The functions called intersect, setdiff, setequal, and union are masked from the R base package.

  • If we use intersect(), setdiff(), setequal(), or union() in our R code, these functions from dplyr will be used since it was the package loaded most recently that contains these functions.

How to Use Masked Functions

Suppose you would like to use the intersect() function from the base R package, but it is currently masked since there is an intersect() function that exists in the dplyr package we loaded more recently.

To explicitly use the intersect() function from base R, you can use the following syntax with double colons:

base::intersect(x, y)

In practice, you’ll most likely load several packages in your R environment at once.

To ensure that you’re using the function from some desired package, you can always type the package name with double colons in front of the function name. 

Additional Resources

The following tutorials explain how to perform other common operations in R:

How to Interpret glm Output in R
How to Interpret ANOVA Results in R
How to Handle R Warning: glm.fit: algorithm did not converge

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories