problem rendering rmarkdown pdf

I've a document that is supposed to produce a personalized report. This contains several tables. When the rmd is rendered from the knit button on Rstudio the document has no problem, but when I do it from witihn R (code is below) the document is rendered but tables lose all it format and are stored as just plain text.

rmarkdown::render(input = "~/Biology/reports/testReport.Rmd", 
                    output_file= tmp,
                    params = list(author= userId,
                                  title= title,
                                  date= Sys.Date(),
                                  taskId= taskId,
                                  alpha= alpha))

I'm not being able to find what might be causing this as there is, technically, no error. my gut feeling tells me that it might be related to some other package overlapping some function, and it's probably related to some bioconductor library, but I've no idea.
this is the session info

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS: /usr/local/R/lib64/R/lib/libRblas.so
LAPACK: /usr/local/R/lib64/R/lib/libRlapack.so

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets methods base

other attached packages:
[1] gtsummary_1.5.2 lme4GS_0.1 ShortRead_1.52.0 GenomicAlignments_1.30.0 BiocParallel_1.28.3
[6] Rsubread_2.8.2 future_1.24.0 snpStats_1.44.0 survival_3.2-13 VariantAnnotation_1.40.0
[11] SummarizedExperiment_1.24.0 Biobase_2.54.0 MatrixGenerics_1.6.0 matrixStats_0.61.0 Rsamtools_2.10.0
[16] Biostrings_2.62.0 XVector_0.34.0 GenomicRanges_1.46.1 GenomeInfoDb_1.30.1 IRanges_2.28.0
[21] S4Vectors_0.32.3 BiocGenerics_0.40.0 pegas_1.1 ape_5.6-2 pdftools_3.1.1
[26] here_1.0.1 properties_0.0-9 PKI_0.1-11 base64enc_0.1-3 yaml_2.3.5
[31] lmerTest_3.1-3 lme4_1.1-28 markdown_1.1 BGLR_1.0.9 jsonlite_1.8.0
[36] mongolite_2.5.0 snpReady_0.9.6 impute_1.68.0 rgl_0.108.3 matrixcalc_1.0-5
[41] Matrix_1.3-4 adegenet_2.1.5 ade4_1.7-18 AGHmatrix_2.0.4 vcfR_1.12.0
[46] promises_1.2.0.1 BiocManager_1.30.16 RCurl_1.98-1.6 tinytex_0.37 plumber_1.1.0.9000
[51] httr_1.4.2 R.utils_2.11.0 R.oo_1.24.0 R.methodsS3_1.8.1 googledrive_2.0.0
[56] poweRlaw_0.70.6 igraph_1.3.1 kableExtra_1.3.4 forcats_0.5.1 stringr_1.4.0
[61] dplyr_1.0.8 purrr_0.3.4 readr_2.1.2 tidyr_1.2.0 tibble_3.1.6
[66] ggplot2_3.3.5 tidyverse_1.3.1 palmerpenguins_0.1.0 ranger_0.13.1 doParallel_1.0.17
[71] iterators_1.0.14 foreach_1.5.2

loaded via a namespace (and not attached):
[1] utf8_1.2.2 tidyselect_1.1.2 RSQLite_2.2.11 AnnotationDbi_1.56.2 htmlwidgets_1.5.4 grid_4.1.2
[7] munsell_0.5.0 codetools_0.2-18 withr_2.5.0 colorspace_2.0-3 filelock_1.0.2 highr_0.9
[13] knitr_1.37 rstudioapi_0.13 listenv_0.8.0 labeling_0.4.2 GenomeInfoDbData_1.2.7 hwriter_1.3.2
[19] farver_2.1.0 bit64_4.0.5 rprojroot_2.0.2 parallelly_1.30.0 vctrs_0.3.8 generics_0.1.2
[25] xfun_0.30 BiocFileCache_2.2.1 qpdf_1.1 R6_2.5.1 bitops_1.0-7 cachem_1.0.6
[31] webutils_1.1 DelayedArray_0.20.0 assertthat_0.2.1 BiocIO_1.4.0 scales_1.1.1 pinfsc50_1.2.0
[37] gtable_0.3.0 globals_0.14.0 rlang_1.0.2 systemfonts_1.0.4 splines_4.1.2 rtracklayer_1.54.0
[43] gargle_1.2.0 broom_0.7.12 reshape2_1.4.4 modelr_0.1.8 GenomicFeatures_1.46.5 backports_1.4.1
[49] httpuv_1.6.5 tools_4.1.2 ellipsis_0.3.2 jquerylib_0.1.4 RColorBrewer_1.1-2 Rcpp_1.0.8.3
[55] plyr_1.8.6 progress_1.2.2 zlibbioc_1.40.0 prettyunits_1.1.1 openssl_2.0.0 zoo_1.8-9
[61] swagger_3.33.1 haven_2.4.3 cluster_2.1.2 fs_1.5.2 magrittr_2.0.3 reprex_2.0.1
[67] truncnorm_1.0-8 hms_1.1.1 mime_0.12 evaluate_0.15 xtable_1.8-4 XML_3.99-0.9
[73] jpeg_0.1-9 readxl_1.3.1 compiler_4.1.2 biomaRt_2.50.3 gt_0.4.0 crayon_1.5.1
[79] minqa_1.2.4 htmltools_0.5.2 mgcv_1.8-38 later_1.3.0 tzdb_0.2.0 lubridate_1.8.0
[85] DBI_1.1.2 dbplyr_2.1.1 broom.helpers_1.6.0 rappdirs_0.3.3 MASS_7.3-54 boot_1.3-28
[91] permute_0.9-7 cli_3.2.0 pkgconfig_2.0.3 numDeriv_2016.8-1.1 xml2_1.3.3 svglite_2.1.0
[97] bslib_0.3.1 webshot_0.5.2 rvest_1.0.2 digest_0.6.29 pracma_2.3.8 vegan_2.5-7
[103] rmarkdown_2.13 cellranger_1.1.0 restfulr_0.0.13 curl_4.3.2 shiny_1.7.1 rjson_0.2.21
[109] nloptr_1.2.2.3 lifecycle_1.0.1 nlme_3.1-153 seqinr_4.2-8 BSgenome_1.62.0 viridisLite_0.4.0
[115] askpass_1.1 fansi_1.0.2 pillar_1.7.0 lattice_0.20-45 KEGGREST_1.34.0 fastmap_1.1.0
[121] glue_1.6.2 png_0.1-7 bit_4.0.4 sass_0.4.0 stringi_1.7.6 blob_1.2.2
[127] latticeExtra_0.6-29 memoise_2.0.1

Without the content (or sample content) of the document in question it will be hard to know what specificity can cause this

If you remove this from the call, does it work better ?

It is best if you have you working directory be in the same as you Rmd report (not using absolute path) and just run rmarkdown::render(input = "testReports.Rmd"

Can you try see if this change something ?

What is the format used ? pdf_document ?

What type of format should it be ?

We need more information to help - for now this is too generic to be able to know what could go wrong.

document.pdf (213.7 KB)
response.pdf (176.7 KB)
Hello, thank you for answering so fast. Because this is actually working within a plumber API it's hard to remove the tmp file, if you desire to see the code, as I cannot attach it I'll copy the full text below. Problem is not with the Rmd as it can be well rendered, just not from console. Attached there are 2 pdfs where show the difference in the render. A priori changing the path on input didn't work. Please let me know about any other information that you would need

---
title: "`r params$title`"
output: pdf_document
params:
  author: "1451396591419719682"
  title: "Draft Report task1"
  date: NA
  taskId: "0c2aff86c1022205fdd901b44d9ec087"
  alpha: .1
author: "`r params$author`"
date: "`r params$date`"
always_allow_html: yes
---

```{r setup, include=FALSE}
source("/home/hadoop/BiologyAPP/BiologyAPI/BiologicalDataAPI/config/config.R")
library("kableExtra")
library("gtsummary")
library("mongolite")
library("yaml")
library("properties")
library("PKI")
library("httr")
library("jsonlite")
library("ggplot2")
knitr::opts_chunk$set(echo = TRUE)
options(warn = -1) 
mongoConfig = loadNacos()
url = paste0("mongodb://",mongoConfig$host,":",mongoConfig$port)
breedingCollection = mongo(db = "servini-aigs",collection = "breedingValues", url = url)
if(params$taskId=="NA"){
  data = breedingCollection$find(paste0('{"userId": "',params$author,'"}'))
}else{
  data = breedingCollection$find(paste0('{"userId": "',params$author,'"',
                                        ', "taskId": "',params$taskId,'"}'))
}

notNull = function(x){
  !is.null(x)
}
alpha = as.numeric(params$alpha)
```

# Cross validation

Lorem ipsum dolor sit amet, consecteturadipiscing elit.  Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
```{r cs, echo=FALSE, results="asis", message=FALSE}
i = 1
for(i  in 1:NROW(data)){
  model = data$model[i]
  variables = names(data$crossValidation$random)
  for(variable in variables){
    if(!is.null(data$crossValidation$random[[variable]][[i]])){
        tmp = data$crossValidation$random[[variable]][[i]]
        tmp$R2_Train = round(tmp$R2_Train, 4)
        tmp$r_Train = round(tmp$r_Train, 4)
        tmp$RMSE_Train = round(tmp$RMSE_Train, 4)
        tmp$R2_Test = round(tmp$R2_Test, 4)
        tmp$r_Test = round(tmp$r_Test, 4)
        tmp$RMSE_Test = round(tmp$RMSE_Test, 4)
        tmp$n_train = round(tmp$n_train)
        tmp$n_test = round(tmp$n_test)
        tmp$ignored = round(tmp$ignored)
        tmp2 = as.data.frame(sapply(tmp, function(x) c( "Stand dev" = sd(x,na.rm=TRUE), 
                         "Mean"= mean(x,na.rm=TRUE))))
        tmp$n_train = formatC(tmp$n_train,format="d")
        tmp$n_test = formatC(tmp$n_test,format="d")
        tmp$ignored = formatC(tmp$ignored,format="d")
        tmp2$n_train = formatC(tmp2$n_train, format="f", digits=2)
        tmp2$n_test = formatC(tmp2$n_test, format="f", digits=2)
        tmp2$ignored = formatC(tmp2$ignored, format="f", digits=2)
        tmp = rbind(tmp, tmp2)
        print(kable(tmp,
                    col.names = c("R2",
                                  "r",
                                  "RMSE",
                                  "R2",
                                  "r",
                                  "RMSE",
                                  "train",
                                  "test",
                                  "unused"), caption = paste0(model,
                                                              ": random effect=",
                                                              variable, 
                                                              ", masking=random"), 
                    digits = 4, booktabs = T, linesep = "", longtable = T) %>%
                kable_styling(position = "float_right") %>%
                add_header_above(c("", "Train" = 3, "Test" = 3, 
                                   "Sample Size" = 3))%>%
                column_spec(1, italic = T) %>%
                row_spec((NROW(tmp)-1):NROW(tmp), bold = T)) 
        }
  }
  variables = names(data$crossValidation$cohort)
  for(variable in variables){
    if(!is.null(data$crossValidation$cohort[[variable]][[i]])){
      tmp = data$crossValidation$cohort[[variable]][[i]]
        tmp$R2_Train = round(tmp$R2_Train, 4)
        tmp$r_Train = round(tmp$r_Train, 4)
        tmp$RMSE_Train = round(tmp$RMSE_Train, 4)
        tmp$R2_Test = round(tmp$R2_Test, 4)
        tmp$r_Test = round(tmp$r_Test, 4)
        tmp$RMSE_Test = round(tmp$RMSE_Test, 4)
        tmp$n_train = round(tmp$n_train)
        tmp$n_test = round(tmp$n_test)
        tmp$ignored = round(tmp$ignored)
        tmp2 = as.data.frame(sapply(tmp, function(x) c( "Stand dev" = sd(x,na.rm=TRUE), 
                         "Mean"= mean(x,na.rm=TRUE))))
        tmp$n_train = formatC(tmp$n_train,format="d")
        tmp$n_test = formatC(tmp$n_test,format="d")
        tmp$ignored = formatC(tmp$ignored,format="d")
        tmp2$n_train = formatC(tmp2$n_train, format="f", digits=2)
        tmp2$n_test = formatC(tmp2$n_test, format="f", digits=2)
        tmp2$ignored = formatC(tmp2$ignored, format="f", digits=2)
        tmp = rbind(tmp, tmp2)
        print(kable(tmp,
                    col.names = c("R2",
                                  "r",
                                  "RMSE",
                                  "R2",
                                  "r",
                                  "RMSE",
                                  "train",
                                  "test",
                                  "unused"), caption = paste0(model,
                                                              ": random effect=",
                                                              variable, 
                                                              ", masking=cohort"), 
                    digits = 4, booktabs = T, linesep = "", longtable = T) %>%
                kable_styling(position = "float_right") %>%
                add_header_above(c("", "Train" = 3, "Test" = 3, 
                                   "Sample Size" = 3))%>%
                column_spec(1, italic = T) %>%
                row_spec((NROW(tmp)-1):NROW(tmp), bold = T)) 
    }
  }
}
```

Lorem ipsum dolor sit amet, consecteturadipiscing elit.  Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.

Lorem ipsum dolor sit amet, consecteturadipiscing elit.  Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.

# Model Summarys

## Bayesian

### Statistics

Lorem ipsum dolor sit amet, consecteturadipiscing elit.  Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
```{r bsum, echo=FALSE, results="asis", message=FALSE}
variables =names(data$GEVs$bayes)
n = 0
for(variable in variables){
  n = n+sum(unlist(lapply(data$GEVs$bayes[[variable]], notNull)))
}
summaryTable = matrix(data = NA, nrow = n, ncol = 8)
colnames(summaryTable) = c("model", "randomEffect", "min", "Q1", "median", "mean", 
                        "Q3", "max")
n=1
for(variable in variables){
  for (i in 1:length(data$GEVs$bayes[[variable]])){
    if(!is.null(data$GEVs$bayes[[variable]][[i]])){
      summaryTable[n,1] = data$model[[i]]
      summaryTable[n,2] = variable
      summaryTable[n,3:8] = round(summary(data$GEVs$bayes[[variable]][[i]][["BV"]]),2)
      n=n+1
    }
  }
}
kable(summaryTable,
      col.names = c("Model",
                    "Breeding Variable",
                    "Minimum",
                    "1st Quantil",
                    "Median",
                    "Mean",
                    "3rd Quantil",
                    "Max"),
      caption = paste0("Bayesian models summary table"),
      digits = 2, booktabs = T, linesep = "", longtable = T) %>%
  kable_styling(position = "float_right") %>%
  column_spec(1:2, italic = T)
```

### Plots

Lorem ipsum dolor sit amet, consecteturadipiscing elit.  Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.
```{r bplot, echo=FALSE, results="asis", message=FALSE}
variables =names(data$GEVs$bayes)
n=1
z = qnorm(1-alpha/2)
for(variable in variables){
  for (i in 1:length(data$GEVs$bayes[[variable]])){
    if(!is.null(data$GEVs$bayes[[variable]][[i]])){
      temp = data$GEVs$bayes[[variable]][[i]]
      colnames(temp)[1] = "id"
      temp = temp[order(-temp$BV),]
      temp = head(data$GEVs$bayes[[variable]][[i]], n=10L)
      colnames(temp)[1] = "id"
      temp$order = NROW(temp):1
      temp$l = temp$BV-z*sqrt(temp$var)
      temp$u = temp$BV+z*sqrt(temp$var)
      p <- ggplot(temp, aes(x=BV, y=factor(order, labels = id), xmin=l, 
                            xmax=u)) +
        geom_pointrange() +
        geom_vline(xintercept = 0, linetype=2) +
        xlab('Breeding Value') +
        ylab('ID') +
        ggtitle(paste0("Effects of ", variable, " according model ", 
                       data$model[i]))
      print(p)
      an=n+1
    }
  }
}
```


## GAME
Lorem ipsum dolor sit amet, consecteturadipiscing elit.  Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.

### Statistics

Lorem ipsum dolor sit amet, consecteturadipiscing elit.  Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.

```{r gsum, echo=FALSE, results="asis", message=FALSE}
variables =names(data$GEVs$blups)
n = 1
for(variable in variables){
  n = n+sum(unlist(lapply(data$GEVs$bayes[[variable]], notNull)))
}
summaryTable = matrix(data = NA, nrow = n, ncol = 8)
colnames(summaryTable) = c("model", "randomEffect", "min", "Q1", "median", "mean", 
                        "Q3", "max")
n=1
for(variable in variables){
  for (i in 1:length(data$GEVs$blups[[variable]])){
    if(!is.null(data$GEVs$blups[[variable]][[i]])){
      summaryTable[n,1] = data$model[[i]]
      summaryTable[n,2] = variable
      summaryTable[n,3:8] = round(summary(data$GEVs$blups[[variable]][[i]][["value"]]),2)
      n=n+1
    }
  }
}
kable(summaryTable,
      col.names = c("Model",
                    "Breeding Variable",
                    "Minimum",
                    "1st Quantil",
                    "Median",
                    "Mean",
                    "3rd Quantil",
                    "Max"),
      caption = paste0("Blups models summary table"),
      digits = 2, booktabs = T, linesep = "", longtable = T) %>%
  kable_styling(position = "float_right") %>%
  column_spec(1:2, italic = T)
```

### Plots

Lorem ipsum dolor sit amet, consecteturadipiscing elit.  Cras sit amet mauris inex ultricies elementum vel rutrum dolor.Phasellus tempor convallis dui, in hendreritmauris placerat scelerisque. Maecenas a ac-cumsan enim, a maximus velit. Pellentesquein risus eget est faucibus convallis nec atnulla. Phasellus nec lacinia justo. Morbifermentum, orci id varius accumsan, nibhneque porttitor ipsum, consectetur luctusrisus arcu ac ex. Aenean a luctus augue. Suspendisse et auctor nisl. Suspendisse cursus ultrices quam nonvulputate. Phasellus et pharetra neque, vel feugiat erat. Sed feugiat elit at mauris commodo consequat. Sedcongue lectus id mattis hendrerit. Mauris turpis nisl, congue eget velit sed, imperdiet convallis magna. Namaccumsan urna risus, non feugiat odio vehicula eget.

```{r gameplot, echo=FALSE, results="asis", message=FALSE}
variables =names(data$GEVs$blups)
n=1
z = qnorm(1-alpha/2)
for(variable in variables){
  for (i in 1:length(data$GEVs$blups[[variable]])){
    if(!is.null(data$GEVs$blups[[variable]][[i]])){
      temp = data$GEVs$blups[[variable]][[i]]
      colnames(temp)[1] = "id" 
      temp = temp[order(-temp$value),]
      temp = head(data$GEVs$blups[[variable]][[i]], n=10L)
      temp$order = NROW(temp):1
      temp$l = temp$value-z*sqrt(temp$var)
      temp$u = temp$value+z*sqrt(temp$var)
      p <- ggplot(temp, aes(x=value, y=factor(order, labels = id), xmin=l, 
                            xmax=u)) +
        geom_pointrange() +
        geom_vline(xintercept = 0, linetype=2) +
        xlab('Breeding Value') +
        ylab('ID') +
        ggtitle(paste0("Effects of ", variable, " according model ", 
                       data$model[i]))
      print(p)
      n=n+1
    }
  }
}
```

Can you at least format the issue correctly

FAQ: How to Format R Markdown Source

If Rmd works well, it means this is something in your environment somehow. When you click render button, it will call rmarkdown::render() in a background session. When you call in R Console, it will use the current environment. Maybe there is a difference in both, or in the way you are calling in console that is different that was is called when clicking the knit button.

Anyway, hard to help more without being able to reproduce. I can only give general hints