Created
April 5, 2023 14:19
-
-
Save matt-dray/e0b4782bd2a23c0b3d6a1f015305171b to your computer and use it in GitHub Desktop.
`rm(list = ls())` probably doesn't do what you think it does
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter(head(presidents), rep(1, 3)) # this uses utils::filter | |
#> Time Series: | |
#> Start = 1 | |
#> End = 6 | |
#> Frequency = 1 | |
#> [1] NA NA 244 220 188 NA | |
library(dplyr, warn.conflicts = FALSE) # attach dplyr | |
search() # shows dplyr will be preferred to utils if there's a nameclash | |
#> [1] ".GlobalEnv" "package:dplyr" "package:stats" | |
#> [4] "package:graphics" "package:grDevices" "package:utils" | |
#> [7] "package:datasets" "package:methods" "Autoloads" | |
#> [10] "tools:callr" "package:base" | |
filter(head(presidents), rep(1, 3)) # defaults now to dplyr::filter, so will error | |
#> Error in UseMethod("filter"): no applicable method for 'filter' applied to an object of class "c('double', 'numeric')" | |
rm(list = ls()) # 'clear workspace', detaches dplyr? | |
filter(head(presidents), rep(1, 3)) # uhoh, it still fails! | |
#> Error in UseMethod("filter"): no applicable method for 'filter' applied to an object of class "c('double', 'numeric')" | |
search() # it's because rm() didn't detach dplyr, so dplyr::filter was used | |
#> [1] ".GlobalEnv" "package:dplyr" "package:stats" | |
#> [4] "package:graphics" "package:grDevices" "package:utils" | |
#> [7] "package:datasets" "package:methods" "Autoloads" | |
#> [10] "tools:callr" "package:base" | |
# A full restart of R will do the job (Session > Restart R, or Ctrl/Cmd+Shift+F10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment