Invalid type (list) for variable using brms::me() in a formula specification

Hello everyone

I’m coding a rather simple model, but I’m stucked while trying to use the me() function of brms:


Glx.Phe <- c(19.6, 19.4, 21.1, 22.1, 20.8, 20.9, 21.3, 21.1,
             21.7, 22.2, 22.7, 22.9, 22.5, 23.0, 22.1, 24.2, 15.2)

Spp <- c("Antarctomysis_maxima", "Antarctomysis_maxima", "Antarctomysis_maxima",
         "Champsocephalus_gunnari", "Champsocephalus_gunnari", "Champsocephalus_gunnari",
         "Champsocephalus_gunnari", "Champsocephalus_gunnari", "Champsocephalus_gunnari",
         "Champsocephalus_gunnari", "Champsocephalus_gunnari", "Champsocephalus_gunnari",
         "Champsocephalus_gunnari", "Electrona_antartica",  "Electrona_antartica", 
         "Electrona_antartica",  "Euphausia_frigida")

tef1 <- rep(7.6, 17)

data <- data.frame(Glx.Phe, Spp, tef1)

formula <- bf(Glx.Phe ~ Spp:me(tef1, 1.2) -1 )

fit <- brm(formula, data = data)


But as I want to use this code within an R package, I need to use pkg::functionname convention. Thus, when I use

formula <- brms::bf(Glx.Phe ~ Spp:brms::me(tef1, 1.2) -1 )
fit <- brms::brm(formula, data = data)

I get the

Error in model.frame.default(all_vars_terms, data, na.action = na.pass, :
invalid type (list) for variable ‘brms::me(tef1, 1.2)’

Any thoughts?

I’m working in win10 with R 4.3.1, rstan 2.26.22 and brms 2.20.1.

Thanks, cheers


1 Like

I suggest to load brms via library(brms) and then just use me() instead of brms::me().

Hi Paul

Thank you very much for the reply. Unfortunately, I would like to use it within a package… I’m implementing a new model for the calculation of trophic position ( which is on GitHub - clquezada/tRophicPosition: estimate trophic position using stable isotope data and also CRAN.

To my knowledge, it wouldn’t work if I load the library in the function I want to use me() from within tRophicPosition, that’s the issue.



1 Like

Can you just import the me function, e.g. with roxoygen comments like so?:

#' @importFrom brms me

Then use as me()?

1 Like

Thanks Ax3man. It didn’t work either.

But I used require(“brms”) within the function and used me() instead of brms::me()



I don’t think CRAN accepts the use of library or require within package code though.

Perhaps you can list brms in Depends in your DESCRIPTION?

1 Like