paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.29k stars 187 forks source link

Many namespace collisions when using conflicted packages #1433

Closed mattmoo closed 1 year ago

mattmoo commented 1 year ago

I am drawing up an analysis pipeline in targets, and using the conflicted package to manage ambiguity (see link).

I am incorporating brms, but the code seems to be particularly ambiguous, which has been frustrating to resolve,

A lot of it seems to revolve around the use of flextable (?) and lubridate without the namespace being clear.

It seems to me that there might be a few places that the code could be tidied up to reduce ambiguity.

library(conflicted)
library(data.table)
library(lubridate)
library(flextable)
library(huxtable)

library(brms)

fit1 <- brm(
  count ~ zAge + zBase * Trt + (1 | patient),
  data = epilepsy,
  family = poisson(),
  chains = 1,
  warmup = 100,
  iter = 500
)

Compiling Stan program...
Error:
! [conflicted] `align` found in 2 packages.
Either pick the one you want with `::` 
* huxtable::align
* flextable::align
Or declare a preference with `conflict_prefer()`
* conflict_prefer("align", "huxtable")
* conflict_prefer("align", "flextable")
Run `rlang::last_error()` to see where the error occurred.

This is how I have resolved the issues in my pipeline, I'm sure that some are erroneous.

conflict_prefer("align", "huxtable")
conflict_prefer("as_flextable", "huxtable")
conflict_prefer("bold", "huxtable")
conflict_prefer("ar", "brms")
conflict_prefer("border", "flextable")
conflict_prefer("continuous_summary", "flextable")
conflict_prefer("dirichlet", "brms")
conflict_prefer("exponential", "brms")
conflict_prefer("font", "flextable")
conflict_prefer("get_y", "brms")
conflict_prefer("height", "flextable")
conflict_prefer("italic", "flextable")
conflict_prefer("rotate", "flextable")
conflict_prefer("theme_apa", "flextable")
conflict_prefer("set_caption", "flextable")
# conflict_prefer("hour", "lubridate")
# conflict_prefer("isoweek", "lubridate")
# conflict_prefer("mday", "lubridate")
# conflict_prefer("week", "lubridate")
# conflict_prefer("minute", "lubridate")
# conflict_prefer("second", "lubridate")
# conflict_prefer("yday", "lubridate")
# conflict_prefer("quarter", "lubridate")
conflict_prefer("lasso", "brms")
conflict_prefer("prior", "brms")
conflict_prefer("quad", "lqmm")
conflict_prefer("read_xlsx", "readxl")
conflict_prefer("theme_grey", "huxtable")
conflict_prefer("to_html", "huxtable")
conflict_prefer("valign", "huxtable")
conflict_prefer("width", "huxtable")
# conflicted::conflict_prefer_all('flextable')
conflicted::conflict_prefer_all('lubridate')
paul-buerkner commented 1 year ago

I don't think this is related to brms to be honest. Almost all of these functions have something to do with other packages. What do you suggest me to do from the brms side?

mattmoo commented 1 year ago

I'm far from an expert package guy, but my observation is that of the 30 or so other packages in the pipeline, none of them throw these errors.

Aside from using package::function notation (which I think is pretty good practice in a package), I notice that lubridate (for instance) is not declared in the DECRIPTION file. Perhaps that would help.

paul-buerkner commented 1 year ago

Lubridate is not imported by brms directly so adding it to namespace or something like that wouldn't help. If I had used something from lubridate accidentally without proper importing, R CMD check would fail with an appropriate warning. But there is nothing that indicates this. It may be that some packages brms imports are in turn importing lubridate but that is not really a concern of brms.

I am sorry these problems occur, but they don't because of what brms does but (perhaps) because of some packages brms imports but has no control over. I don't think there is anything I can do about that from the brms side unfortunately.

Thus I will close this issue but feel free to reopen it if is becomes apparent that it is indeed related to brms directly.