For that you first have to pass the data to the function :

library(dplyr)

library(lme4)

model <- function(data, x){

lmer(paste("cyl ~", x, "+", "(1|disp)"), data = data)

}

and then try to call it like the following :

mtcars %>% model('hp')

#Linear mixed model fit by REML ['lmerMod']

#Formula: cyl ~ hp + (1 | disp)

# Data: data

#REML criterion at convergence: 96.2

#Random effects:

# Groups Name Std. Dev.

# disp (Intercept) 0.927

# Residual 0.441

#Number of obs: 32, groups: disp, 27

#Fixed Effects:

#(Intercept) hp

# 3.1866 0.0196