Reputation: 837
I just updated all my packages and restarted my system. Then I loaded RStudio and preceded to run my scripts as normal.
I got an error: Error in wday(temp_date) : could not find function "wday"
Searching, I found the wday
function is part of the lubricate package, and I have the lubricate
package installed, but not loaded.
So it seems that at least one of my updated packages previously was dependent on the lubricate package, but is not anymore, as a result even though my scripts loaded all the same packages as before, the lubricate package was missed.
So to prevent this is the future I would like to know how to find out what loaded the lubricate package from my script and if possible to know what changed. I would also like to know all of my package dependencies so I always know that this package loads that and other package so I am not surprised like this anymore.
Update:
I found more errors and slowly worked out that many packages and dependencies were not actually updated and had to be installed manually.
I found that wday
that I am using is from IDateTime from data.table. But once again I am not loading these packages directly, so how can I find out what actually loaded them.
Thanks.
Update 2: Here is my full list of library calls:
library(qmao);library(chron);library(tseries);library(iterators);library(erer);
library(corpcor); library(zoo); library(xts); library(quantmod);
library(TTR); library(graphics); library(ggplot2); library(gsee);
library(tseries); library(quantstrat); library(plyr); library(caTools);
library(zoo); library(chron); library(gtools); library(microbenchmark);
library(benchmark); library(rbenchmark); library(utils); library(Rcpp);
library(RcppXts); library(RcppArmadillo); library(gtools); library(rcppbugs);
library(RcppClassic); library(RcppStreams); library(inline); library(RcppEigen);
library(RcppParallel); library(RcppProgress); library(doParallel); library(parallel);
library(foreach); library(doMC); library(doSNOW); library(fGarch); library(FitAR);
library(fUnitRoots); library(dplyr);
None of them include lubricate or data.table so still don't know. I suppose I could go 1 by 1 loading each library until the functions work, but I really don't have the time or patience for that. Thanks again.
Upvotes: 2
Views: 860
Reputation: 160447
I'm not an R-internals or R-Core guy, so some of this is speculation and understanding on my part.
If a package imports functions from another package, either one-by-one or the whole other-package, then those functions should not be inserted into your search path. For example, dplyr
is a fairly complex package that imports from several other packages and optionally re-exports some of them. For instance, from its NAMESPACE
:
importFrom(R6,R6Class)
but if you library(dplyr)
and then type in R6Class
, it reports Error: object 'R6Class' not found
. However, it is visible to dplyr
functions:
> R6Class
Error: object 'R6Class' not found
> debug(dplyr::mutate)
> mutate(mtcars, cyl = 5)
debugging in: mutate(mtcars, cyl = 5)
debug: {
UseMethod("mutate")
}
Browse[2]> R6Class
function (classname = NULL, public = list(), private = NULL,
active = NULL, inherit = NULL, lock_objects = TRUE, class = TRUE,
portable = TRUE, lock_class = FALSE, cloneable = TRUE, parent_env = parent.frame(),
lock)
{
...
This works now because the search path within dplyr::mutate
is from dplyr
's perspective, not the user's perspective.
Combine with this my doubt (though not certainty) that those packages would call library(data.table)
, importing the package into your search path.
More than likely, there is a package imported by one of the packages you just listed (a second-generation dependency-import, I guess) that is improperly referencing wday
by itself, and it just starts working when some higher package is properly loaded, bringing that function into its effective search path.
I suggest two ways to find what is going wrong:
When you see an error, run traceback()
and look at the stack of function calls; it'll take some sleuthing, but find where that wday
is being called, find that function in the packages (both exported and internal functions!), and go from there.
If all packages are being thorough in announcing packages they import (via Depends:
, Imports:
, or perhaps even a mis-used Suggests:
), then you can hunt down where nested dependencies go with something like this.
pkgs <- trimws(unlist(strsplit(gsub("library\\(([^)]*)\\)", "\\1", "library(qmao);library(chron);library(tseries);library(iterators);library(erer);
library(corpcor); library(zoo); library(xts); library(quantmod);
library(TTR); library(graphics); library(ggplot2); library(gsee);
library(tseries); library(quantstrat); library(plyr); library(caTools);
library(zoo); library(chron); library(gtools); library(microbenchmark);
library(benchmark); library(rbenchmark); library(utils); library(Rcpp);
library(RcppXts); library(RcppArmadillo); library(gtools); library(rcppbugs);
library(RcppClassic); library(RcppStreams); library(inline); library(RcppEigen);
library(RcppParallel); library(RcppProgress); library(doParallel); library(parallel);
library(foreach); library(doMC); library(doSNOW); library(fGarch); library(FitAR);
library(fUnitRoots); library(dplyr);"), ";")))
# just so I can search locally on mine without all of those packages
inst_pkgs <- installed.packages()
pkgs <- intersect(pkgs, inst_pkgs[,1])
# inexact but "good enough" for now
possibles <- Filter(function(a) any(grepl("data.table|lubridate", a)),
sapply(pkgs, function(p) unlist(packageDescription(p)[c("Depends","Imports","Suggests")])))
names(possibles)
# [1] "dplyr"
You can find more info by looking at the full details of that package:
possibles[[1]]["Suggests"]
# Suggests
# "bit64 (>= 0.9.7), callr (>= 3.1.1), covr (>= 3.0.1), DBI (>=\n0.7.14), dbplyr (>= 1.2.0), dtplyr (>= 0.0.2), ggplot2 (>=\n2.2.1), hms (>= 0.4.1), knitr (>= 1.19), Lahman (>= 3.0-1),\nlubridate (>= 1.7.4), MASS, mgcv (>= 1.8.23), microbenchmark\n(>= 1.4.4), nycflights13 (>= 0.2.2), rmarkdown (>= 1.8), RMySQL\n(>= 0.10.13), RPostgreSQL (>= 0.6.2), RSQLite (>= 2.0),\ntestthat (>= 2.0.0), withr (>= 2.1.1), broom (>= 0.5.1), purrr\n(>= 0.3.0), readr (>= 1.3.1), crayon (>= 1.3.4)"
Upvotes: 1