# Changing objective functions with penalty term in XGboost in R

I basically have something like:

xgbmod = xgboost(data = data.matrix(train_s), booster = "gblinear",
nround = 100, #max_depth=10, lambda=0.5,
label = data.matrix(train_df\$ss),
objective = "reg:squarederror")


You can see the current objective function is squared error loss.

I want to define a new objective function:

(pred - true)^2 + penalty*(a variable in my data)

So I want to penalize on a variable in my data.

How can I change the objective function to this using XGboost function in R? Is there a way that to define the loss function without touching the source code of it. Because the pred is changing, as we have the penalty term, and I think we cannot use any existing model.