Skip to content

Commit 1ea13d4

Browse files
committed
Suggest stats::lag() in dplyr::lag() warning
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.
1 parent 2f5b4f9 commit 1ea13d4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Authors@R: c(
88
person(given="Ross", family="Bennett", role="ctb"),
99
person(given="Corwin", family="Joy", role="ctb")
1010
)
11-
Depends: zoo (>= 1.7-12)
11+
Depends: R (>= 3.6.0), zoo (>= 1.7-12)
1212
Imports: methods
1313
LinkingTo: zoo
1414
Suggests: timeSeries, timeDate, tseries, chron, tis, tinytest

R/zzz.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,16 @@ function(pkg, generic, class, fun = NULL)
5454

5555
.onAttach <- function(libname, pkgname)
5656
{
57-
if (getOption("xts.warn_dplyr_breaks_lag", TRUE)) {
57+
warn_dplyr_lag <- getOption("xts.warn_dplyr_breaks_lag", TRUE)
58+
59+
dplyr_will_mask_lag <- conflictRules("dplyr")
60+
if (is.null(dplyr_will_mask_lag)) {
61+
dplyr_will_mask_lag <- TRUE
62+
} else {
63+
dplyr_will_mask_lag <- all(dplyr_will_mask_lag$exclude != "lag")
64+
}
65+
66+
if (warn_dplyr_lag && dplyr_will_mask_lag) {
5867

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

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

0 commit comments

Comments
 (0)