Skip to content

Commit

Permalink
Suggest stats::lag() in dplyr::lag() warning
Browse files Browse the repository at this point in the history
Also suggest users set conflictRules() to prevent dplyr from breaking
base R's behavior. Add dependency on R-3.6.0 or greater because that's
when conflictRules() was introduced.
  • Loading branch information
joshuaulrich committed Feb 20, 2023
1 parent 2f5b4f9 commit 1ea13d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Authors@R: c(
person(given="Ross", family="Bennett", role="ctb"),
person(given="Corwin", family="Joy", role="ctb")
)
Depends: zoo (>= 1.7-12)
Depends: R (>= 3.6.0), zoo (>= 1.7-12)
Imports: methods
LinkingTo: zoo
Suggests: timeSeries, timeDate, tseries, chron, tis, tinytest
Expand Down
15 changes: 14 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ function(pkg, generic, class, fun = NULL)

.onAttach <- function(libname, pkgname)
{
if (getOption("xts.warn_dplyr_breaks_lag", TRUE)) {
warn_dplyr_lag <- getOption("xts.warn_dplyr_breaks_lag", TRUE)

dplyr_will_mask_lag <- conflictRules("dplyr")
if (is.null(dplyr_will_mask_lag)) {
dplyr_will_mask_lag <- TRUE
} else {
dplyr_will_mask_lag <- all(dplyr_will_mask_lag$exclude != "lag")
}

if (warn_dplyr_lag && dplyr_will_mask_lag) {

dplyr_path <- find.package("dplyr", quiet = TRUE, verbose = FALSE)

Expand Down Expand Up @@ -85,6 +94,10 @@ function(pkg, generic, class, fun = NULL)
# mechanism. #
# #
# Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning. #
# #
# You can use stats::lag() to make sure you're not using dplyr::lag(), or you #
# can add conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop #
# dplyr from breaking base R's lag() function. #
################################### WARNING ###################################")
packageStartupMessage(msg)
}
Expand Down

0 comments on commit 1ea13d4

Please sign in to comment.