I'm using rmarkdown in R studio. I'm attempting to create a descriptive summary table of the variables in the data.frame. I can knit the whole file and it will produce a working PDF with the table. But the moment I run this chunk, it gives me the error:
Error in sub(re, "", x, perl = TRUE) : input string 6 is invalid UTF-8
It comes up whenever I directly call my built summary table. Whenever I call "summary_table" or "descriptive table it gives me the stated error. I don't know what to do! The weird thing is its able to knit the whole rmarkdown file into a pdf with no problem.
(chunk starts here)
``{r, results='asis', echo = F}
library(qwraps2)
Considered_Variables <- data.frame(female, age, attractive_important, sincere_important, intellicence_important, funny_important, ambtition_important, shared_interests_important,decision,match)
descriptive_analysis <- list("Female" =
list("Minimum value" =~ min(female),
"Maximum Value" =~ max(female),
"Median" =~median(female),
"Standard deviation" =~ sd(female),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(female)),
"Age" =
list("Minimum Value" =~ min(age),
"Maximum Value" =~ max(age),
"Median" =~median(age),
"Standard deviation" = ~ sd(age),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(age)),
"Importance given to attractiveness" =
list("Minimum Value" =~ min(attractive_important),
"Maximum Value" =~ max(attractive_important),
"Median" =~median(attractive_important),
"Standard deviation" = ~ sd(attractive_important),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(attractive_important)),
"Importance given to attractiveness" =
list("Minimum Value" =~ min(sincere_important),
"Maximum Value" =~ max(sincere_important),
"Median" =~median(sincere_important),
"Standard deviation" = ~ sd(sincere_important),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(sincere_important)),
"Importance given to intelligence" =
list("Minimum Value" =~ min(intellicence_important),
"Maximum Value" =~ max(intellicence_important),
"Median" =~median(intellicence_important),
"Standard deviation" = ~ sd(intellicence_important),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(intellicence_important)),
"Importance given to funny traits" =
list("Minimum Value" =~ min(funny_important),
"Maximum Value" =~ max(funny_important),
"Median" =~median(funny_important),
"Standard deviation" = ~ sd(funny_important),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(funny_important)),
"Importance given to professional ambition" =
list("Minimum Value" =~ min(ambtition_important),
"Maximum Value" =~ max(ambtition_important),
"Median" =~median(ambtition_important),
"Standard deviation" = ~ sd(ambtition_important),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(ambtition_important)),
"Importance given to shared interests" =
list("Minimum Value" =~ min(shared_interests_important),
"Maximum Value" =~ max(shared_interests_important),
"Median" =~median(shared_interests_important),
"Standard deviation" = ~ sd(shared_interests_important),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(shared_interests_important)),
"Decision" =
list("Minimum Value" =~ min(decision),
"Maximum Value" =~ max(decision),
"Median" =~median(decision),
"Standard deviation" = ~ sd(decision),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(decision)),
"Match" =
list("Minimum Value" =~ min(match),
"Maximum Value" =~ max(match),
"Median" =~median(match),
"Standard deviation" = ~ sd(match),
"Mean ± Standard deviation" = ~ qwraps2::mean_sd(match)))
orig_opt <- options()$qwraps2_markup
options(qwraps2_markup = "markdown")
descriptive_table <- summary_table(Considered_Variables, descriptive_analysis )
print(descriptive_table,
caption = " Descriptive Table",
rtitle = "Variables",
cnames = c("Values"))
``
(chunk ends here)
The screenshot is the PDF produced, as you can see there is no issue in the end result
I'm a noob in this website/community, so if I'm missing any crucial information to make this issue clearer just let me know.
Thank you very much!
The answer is simple, it seems the ± symbol is not supported and it was causing the error message. While it did not impede the file from being correctly knit and from producing a clear PDF in markdown, it did show up as an error when the chunk ran.