No parameter log_lik

why in rmarkdown i get the error " Error in check_pars(allpars,pars) : no parameter log_lik"
and if i run this code in my Rstudio console is ok?


logisticLoo = "data {
  int<lower=0> N;             // number of data points
  int<lower=0> P;             // number of predictors (including intercept)
  matrix[N,P] X;              // predictors (including 1s for intercept)
  int<lower=0,upper=1> y[N];  // binary outcome
}
parameters {
  vector[P] beta;
}
model {
  beta ~ normal(0, 1);
  y ~ bernoulli_logit(X * beta);
}
generated quantities {
  vector[N] log_lik;
  for (n in 1:N) {
    log_lik[n] = bernoulli_logit_lpmf(y[n] | X[n] * beta);
  }
}"

data(birthwt)
head(birthwt)
as.factor(birthwt$low)
X <- model.matrix(~ race+bwt,birthwt)
standata <- list(y =birthwt$low , X = X, N = nrow(X), P = ncol(X))

# Fit model
fit_1 <- stan(model_code =  logisticLoo,
              data = standata)

pars = c("log_lik")
# Extract pointwise log-likelihood and compute LOO
log_lik_1 <- extract_log_lik(fit_1,parameter_name = pars, merge_chains = FALSE)

# as of loo v2.0.0 we can optionally provide relative effective sample sizes
# when calling loo, which allows for better estimates of the PSIS effective
# sample sizes and Monte Carlo error
r_eff <- relative_eff(exp(log_lik_1)) 

loo_1 <- loo(log_lik_1, r_eff = r_eff, cores = 2)
print(loo_1)

standata$X[, "bwt"] <- log(standata$X[, "bwt"])
fit_2 <- stan(fit = fit_1, data = standata) 

log_lik_2 <- extract_log_lik(fit_2,parameter_name = pars, merge_chains = FALSE)
r_eff_2 <- relative_eff(exp(log_lik_2))
loo_2 <- loo(log_lik_2, r_eff = r_eff_2, cores = 2)
print(loo_2)
# Compare
comp <- loo_compare(loo_1, loo_2)
print(comp)

This looks ok on the Stan side. You should post the rmarkdown block, the error must be there.