Problem with encoding for Rmarkdown in Loop

Dear all I have one problem.

I have one .Rmd file (named loop.Rmd), in which i have some text outside che chunks with special simbols(accents, apostrophe). If I generate the PDF by Knit, in the output this symbols are correct.

My problem is that I have another file main_loop.R in which I use a loop to generate some PFDs based on loop.Rmd file. I use the render function to produce them. My problem is that in these PDF the symbols are wrong (è as è, ' as ’ and so on)..

I try to solve the problem including the following latex codes in the loop.Rmd file:

  • \usepackage[T1]{fontenc}
  • \usepackage[utf8]{inputenc}
  • \usepackage[italian]{babel}

But it doesent't work...
I also try by adding encoding = "UTF-8" in render function and options(encoding = 'UTF-8') but it doesn't work
anyone has any ideas???

Thanks a lot


Are you passing content to the Rmd file inside the loop ? Are your file encoding as UTF-8 ?

The knit button is calling rmarkdown::render() so it should work the same, unless you are doing something special in your R file.

Can you try to share a reproducible example ?

I try to create a script easier to share share with you.. and now it worked, I also add the other lines of code and it works... I don't understard, maybe I only change the order of che command at the beginning of the Rmd file.

Thank you and sorry



Great ! Happy to hear that!

This is one of the benefit of trying to build a reprex. You may solve, consciously or not, the problem you had in the first place!

Glad it works now!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.