Hi,
I use Rmarkdown and bookdown to write my thesis currently and got stuck for several hours on an error I hope the community can help me solve. Below is a reproducible example (Rmarkdown source code). When rendering, I keep on getting the following error:
! LaTeX Error: Unicode character (U+2009) not set up for use with LaTeX (...) Execution halted
---
title: "Untitled"
output: pdf_document
date: "2023-11-20"
---
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE)
library(rvest)
library(tidyverse)
library(kableExtra)
# download table and store in tbl
url <- "https://www.nature.com/articles/s41598-020-66404-z/tables/1"
html_content <- read_html(url)
tables <- html_table(html_content, fill = TRUE)
tb <- tables[[1]]
# now I reformat the table according to the original (see url for original)
ref_names <- tb[[1]]
tb <- tb[c(2:3, 5:7, 9:11, 13:15, 17:19, 21:23, 25:27, 29:31, 33:35, 37:39, 41:43, 45:46, 48:49), ]
cap <- "Descriptive statistics for demographic variables of infants and mothers included in the present study."
# the colnames do not work with mutate_all so I store them temporarily
# also they contain a unicode character I remove before reusing them
cnames <- colnames(tb)
str_detect(cnames, "\u2009")
cnames <- str_replace_all(cnames, "\u2009", " ")
colnames(tb) <- make.names(colnames(tb))
tb <- mutate_all(tb, function(x) str_replace_all(x, "\\\\([()])", "\\1"))
colnames(tb) <- cnames
table1 <- kbl(tb, booktabs = TRUE, caption = cap, escape = FALSE) %>%
pack_rows("Gender", 1, 2) %>%
pack_rows("Age (days) PRE", 3, 5) %>%
pack_rows("Age (days) POST", 6, 8) %>%
pack_rows("Maternal Age (years)", 9, 11) %>%
pack_rows("Birthweight (grams)", 12, 14) %>%
pack_rows("Breastfeeding (Birth - PRE)", 15, 17) %>%
pack_rows("Breastfeeding (PRE - POST)", 18, 20) %>%
pack_rows("Formula-feeding (Birth - PRE)", 21, 23) %>%
pack_rows("Formula-feeding (PRE - POST)", 24, 26) %>%
pack_rows("Proportion breastfeeding (Birth - PRE)", 27, 29) %>%
pack_rows("Proportion breastfeeding (PRE - POST)", 30, 32) %>%
pack_rows("Siblings", 33, 34) %>%
pack_rows("C-Section", 35, 36)
table1