Error while while knit in a OneDrive synced folder

The script below throws an error (see below) if knitted (both normal and notebook files) but only if the file is synced in OneDrive. If I put the file in the desktop, no error is given.

My default RStudio encoding is UTF-8.

My locale is > >"LC_COLLATE=Italian_Italy.1252;LC_CTYPE=Italian_Italy.1252;LC_MONETARY=Italian_Italy.1252;L>C_NUMERIC=C;LC_TIME=Italian_Italy.1252"

mycontrols  <- tableby.control(test=TRUE, total=F,
                               numeric.test="kwt", cat.test="fe",
                               numeric.stats=c("N","range", "medianq1q3",
                                               "meansd", "Nmiss"),
                               stats.labels=list(N='Count', median='Median', q1q3='Q1,Q3',mean='Mean', meansd="Mean (SD)"),

tab.test <- tableby( carb ~ .,
                     data= mtcars, 
summary(tab.test, text = T)


BlockquoteError in gsub(""", "\"", string, fixed = TRUE) : input string 2 is invalid UTF-8
13.gsub(""", "\"", string, fixed = TRUE)
12.paste0(""", gsub(""", "\"", string, fixed = TRUE), """)
9.paste(quoted(args), collapse = " ")
8.paste(quoted(pandoc()), paste(quoted(args), collapse = " "))
7.rmarkdown::pandoc_convert(input = rmarkdown::pandoc_path_arg(mdfile), to = "html", output = >rmarkdown::pandoc_path_arg(htmlfile))
4.print.knitr_kable(knitr::kable(df[[i]], caption = NULL, align = attr(df[[i]], "align"), format = format, >row.names = FALSE, escape = escape, ...))
3.print(knitr::kable(df[[i]], caption = NULL, align = attr(df[[i]], "align"), format = format, row.names = >FALSE, escape = escape, ...))
1.(function (x, ...) UseMethod("print"))(x)

Hi @lucavd and welcome.

This is a strange error to get with this code.

I copied your code into an RMarkdown file and was able to knit it to HTML just fine. The same result when I saved it to my OneDrive folder and synced it.

Can you be sure that you are running only this code that you have included in your post? is there any other context? What does your whole file look like?

I have a different locale to you but am also using UTF-8.