Get startedGet started for free

The Conflicted Package

Great package authors think alike. This means they often come up with the same function name. In base R, there is a function called lag() that is used in time-series. In the dplyr package, a similarly named function used to next values in a vector.

You are going to use the conflicted package to handle this issue.

This exercise is part of the course

Defensive R Programming

View Course

Exercise instructions

  • Load the dplyr and conflicted packages.
  • Use conflict_prefer() to select the dplyr version of lag().
  • Test the lag() function and verify it gives the expected output. This has been done for you.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Load the dplyr and conflicted packages
library("___")
library("___")

# Prefer the dplyr version of the lag function
conflict_prefer("___", "___")

# This should return NA, 1, 2, 3
lag(1:4)
Edit and Run Code