Running your code with minor fixes
product <- structure(list(date = c("2022-11", "2022-10", "2022-09", "2022-08", "2022-07", "2022-06"),
production_brute_nucleaire = c(22951.429, 21465.026, 19334.531, 19319.365, 19923.664, 21275.248)),
row.names = c(NA, 6L),
class = "data.frame")
> str(product)
'data.frame': 6 obs. of 2 variables:
$ date : chr "2022-11" "2022-10" "2022-09" "2022-08" ...
$ production_brute_nucleaire: num 22951 21465 19335 19319 19924 ...
library(recipes)
rec <- recipe(~., data = product)
bc_trans <- step_BoxCox(rec, all_numeric())
> bc_estimates <- prep(bc_trans, training = product)
Warning message:
In optimize(bc_obj, interval = limits, maximum = TRUE, dat = dat, :
NA/Inf replaced by maximum positive value
bc_data <- bake(bc_estimates, product)
plot(density(product$production_brute_nucleaire), main = "before")
gives this
Remark 1 You have to be careful when applying the Box-Cox transformation to a time-series variable though. The derivation of the likelihood function in the Box-Cox transformation (G.E.P. Box and D.R. Cox, An Analysis of Transformations, Journal of the Royal Statistical Society. Series B (Methodological), Vol. 26, No. 2 (1964), pp. 211-252) presumes independent observations, an assumption which may not be met in a time-series context.