R Reports - R markdown- knitr pandoc - The input must be a UTF-8 encoded text. hilariagrieve  2021-05-19 08:19
Status: Closed
 

Hi,
I have installed The last version of labkey Server in a new Server and I reload the study folder with some troubleshoots but finally I did it.
But, I have problems with R reports. I remember that I have the same problem with the old server and I solve It but I don't know how.
I was researching and tried a lot of things but I didn't make it.
The problem is with r markdown, knitr and the error is that the imput must be a UTF-8 encondec text, and The file script.Rmd is not encoded in UTF-8.
I tried to set the File : Save with Encoding UTF-8 in R studio like https://support.rstudio.com/hc/en-us/articles/200532197-Character-Encoding.

Here is the log file:

Error executing command
javax.script.ScriptException: javax.script.ScriptException: An error occurred when running the script 'script.R', exit code: 1).

processing file: script.Rmd

|
| | 0%
|
|.......... | 14%
ordinary text without R code

|
|.................... | 29%
label: labkey (with options)
List of 1
$ echo: logi FALSE

|
|.............................. | 43%
ordinary text without R code

|
|........................................ | 57%
label: setup (with options)
List of 7
$ echo : logi FALSE
$ cache : logi TRUE
$ results : chr "hide"
$ warning : logi FALSE
$ comment : logi FALSE
$ message : logi FALSE
$ comments: chr ""

Loading required package: httr
Loading required package: jsonlite
Executing: pandoc -t html -o "script.html" "script.Rmd"
[WARNING] Could not deduce format from file extension .Rmd
Defaulting to markdown
UTF-8 decoding error in script.Rmd at byte offset 995 (e9).
The input must be a UTF-8 encoded text.
Quitting from lines 24-32 (script.Rmd)
Error in (function (input, format, ext, exec, cfg) : conversion failed
Calls: render ... eval -> eval -> <Anonymous> -> mapply -> <Anonymous>
Adem�s: Warning messages:
1: In readLines(con, warn = FALSE) :
entrada inv�lida encontrada en la conexi�n de entrada 'script.Rmd'
2: In xfun::read_utf8(input) :
The file script.Rmd is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 15, 46, 53, 59, 61, 72, ...
3: In read_utf8(input[1]) :
The file script.Rmd is not encoded in UTF-8. These lines contain invalid UTF-8 characters: 15, 46, 53, 59, 61, 72, ...

Ejecuci�n interrumpida

 
 
hilariagrieve responded:  2021-05-19 08:20
Status: Active
This is the script

---
title: "Informe General"
output: html_document
---


```{r setup, echo=FALSE, cache=TRUE, results='hide', warning=FALSE, comment=FALSE, warning=FALSE, message=FALSE, comments = ""}
library(RCurl);
library(Rlabkey);
labkey.setCurlOptions(ssl_verifypeer=FALSE, ssl_verifyhost=FALSE);
library(knitr);
knitr::opts_chunk$set(echo=FALSE, cache=FALSE, comment=FALSE, comments ="", warning=FALSE, eval = TRUE, encoding = "native.enc")
#knitr::opts_chunk$get();
knitr::pandoc('script.Rmd', format='html')
#knitr::pandoc('script.Rmd', format='latex', config="Script.pdf")
```

```{r results = 'asis', echo=FALSE}
library(xtable);
library(stringr);
labkey.data <- read.table("${input_data}", header=TRUE, sep="\t", fileEncoding = "UTF-8", fill = TRUE)
#names(labkey.data);
#kable(head(labkey.data),format = "markdown", caption = "Informe",digits = getOption("digits"), row.names = NA , col.names = NA, align="l", format.args = list(), booktabs=TRUE, longtable=TRUE, escape = TRUE, encoding = 'UTF-8')
 
Jon (LabKey DevOps) responded:  2021-06-03 17:04
Status: Closed
Hi Hilaria,

This looks like a Pandoc issue rather than an R issue.

Do you know what version of Pandoc you're running?

An initial search shows this very problem with pandoc here:

https://stackoverflow.com/questions/47954642/pandoc-complains-about-utf-8-decoding-error-even-if-my-file-is-valid-utf-8-encod

Also, because you said this is a new server, did you remember to copy all of your old R packages over, such as the utf8 package and other ones?

https://cran.r-project.org/web/packages/utf8/utf8.pdf

Maybe your new server isn't fully equipped as your old one due to a package discrepancy?

Regards,

Jon