Skip to content

ioslides_presentation "Invalid UTF-8 stream" error with   #134

Closed

Description

@jrowen

I'm using render to create an ioslides presentation with a table generated from pandoc.table and am running into the following error:

pandoc.exe: Cannot decode byte '\xa0': Data.Text.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream

The error appears to be caused by pandoc.table returning   for the first column header, as removing   eliminates the error. Below is an Rmd file that can be used to reproduce the error message. The same error message occurs when using the Knit HTML button in RStudio.


---
title: "Untitled"
output: ioslides_presentation

---

## Slide

```{r, echo=FALSE, results='asis'}
library(pander)

m <- mtcars[1:2, 1:3]

# error
pandoc.table(m, style = "rmarkdown")

# success
ptable = function(...) {
  cat(paste0(gsub("&nbsp;", "      ",
                  pander.return(...)), collapse = "\n"))
}
# ptable(pandoc.table(m, style = "rmarkdown"))
```

Activity

  1. yihui commented on Jun 21, 2014

    @yihui
    Collaborator

    I cannot reproduce the problem with R 3.1.0 under Windows (from your pandoc.exe I guess you were using Windows). Please report your session info:

    library(rmarkdown)
    library(knitr)
    library(pander)
    sessionInfo()
  2. jrowen commented on Jun 21, 2014

    @jrowen
    Author

    Below is the my session info and the full output from rendering the markdown document. Let me know if there is anything else I can provide.

    Output from sessionInfo():

    > library(rmarkdown)
    > library(knitr)
    > library(pander)
    
    Attaching package: ‘pander’
    
    The following object is masked from ‘package:knitr’:
    
        pandoc
    
    > sessionInfo()
    R version 3.1.0 (2014-04-10)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    
    locale:
    [1] LC_COLLATE=English_United States.1252 
    [2] LC_CTYPE=English_United States.1252   
    [3] LC_MONETARY=English_United States.1252
    [4] LC_NUMERIC=C                          
    [5] LC_TIME=English_United States.1252    
    
    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     
    
    other attached packages:
    [1] pander_0.3.8     knitr_1.6        rmarkdown_0.2.46
    
    loaded via a namespace (and not attached):
    [1] digest_0.6.4    evaluate_0.5.5  formatR_0.10    htmltools_0.2.4
    [5] stringr_0.6.2   tools_3.1.0     yaml_2.1.13 
    

    Output from render():

    > render("c:/data/test.Rmd")
    
    
    processing file: test.Rmd
      |................................                                 |  50%
      ordinary text without R code
    
      |.................................................................| 100%
    label: unnamed-chunk-1 (with options) 
    List of 2
     $ echo   : logi FALSE
     $ results: chr "asis"
    
    
    output file: test.knit.md
    
    "C:/Program Files/RStudio/bin/pandoc/pandoc" test.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output test.html --smart --email-obfuscation none --self-contained --variable transition=0.4 --template C:\Users\jrowen\Documents\R\win-library\3.1\rmarkdown\rmd\ioslides\default.html --mathjax --variable mathjax-url:https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML --variable ioslides-url=C:\Users\jrowen\Documents\R\win-library\3.1\rmarkdown\rmd\ioslides\ioslides-13.5.1 
    "C:/Program Files/RStudio/bin/pandoc/pandoc" test.utf8.md --to ioslides_presentation.lua --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output C:\Users\jrowen\AppData\Local\Temp\Rtmpk1JdmA\ioslides-output14542bc17545.html --data-dir . 
    Error: pandoc document conversion failed with error 1
    In addition: Warning message:
    running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" test.utf8.md --to ioslides_presentation.lua --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output C:\Users\jrowen\AppData\Local\Temp\Rtmpk1JdmA\ioslides-output14542bc17545.html --data-dir .' had status 1
    
  3. yihui commented on Jun 26, 2014

    @yihui
    Collaborator

    Sorry, I really cannot reproduce it with exactly the same environment as yours. Can you send me your Rmd file by email? yihui[at]rstudio.com

  4. yihui commented on Jun 26, 2014

    @yihui
    Collaborator

    BTW, if all you want is a simple table, you can also try knitr::kable(m) instead of pandoc.table(m).

  5. jrowen commented on Jun 27, 2014

    @jrowen
    Author

    My Rmd file consists only of the code shown in my first post above. Interestingly, if I change to output: beamer_presentation, I don't receive any errors. The problem is consistently reproducible with output: ioslides_presentation on my machine, so if there is anything else I can provide, let me know.

    I also use kable but in this case was trying to leverage the row and column emphasize functionality of pandoc.table.

    This question may provide more insight. Could the default text encoding on my machine be causing this problem? I'm using RStudio to execute scripts, and under Tools->General ->Default text encoding I see [Ask], but clicking Change lists ISO-8859-1 as the System Default.

    Below is the raw utf8.md and knit.md data.

    ---
    title: "Untitled"
    output: ioslides_presentation
    ---
    
    ## Slide
    
    
    |       &nbsp;        |  mpg  |  cyl  |  disp  |
    |:-------------------:|:-----:|:-----:|:------:|
    |    **Mazda RX4**    |  21   |   6   |  160   |
    |  **Mazda RX4 Wag**  |  21   |   6   |  160   |
    
  6. jrowen commented on Jun 27, 2014

    @jrowen
    Author

    Getting closer here, I think the problem may be related to the encoding used to save the Rmd file (I'm currently using the default RStudio settings described above). When I open the Rmd file in Notepad++, the Encoding menu lists it as ANSI. Using Notepad++, if I choose Encoding->Covert to UTF-8 and re-save the file, render runs with only a warning. The resulting html file is missing a title slide, but I believe this is due to a BOM () being added to the file as part of the conversion. I see the following html where the title slide should be:

    <div class="container-fluid main-container">
    
    
    
    
    <p>— title: “Untitled” output: ioslides_presentation —</p>
    <div id="slide" class="section level2">
    
  7. yihui commented on Jun 27, 2014

    @yihui
    Collaborator

    I think you are on the right track. You should re-save the Rmd file with the UTF-8 encoding (menu File > Save with encoding). I also recommend you to change your default text encoding to UTF-8.

    I'll see if I can reproduce the problem with your text encoding and fix it. Thanks!

  8. jrowen commented on Jun 27, 2014

    @jrowen
    Author

    Same Invalid UTF-8 stream error if I save as UTF-8 via RStudio. Only way I've been able to get the file to run is if I convert to UTF-8 via Notepad++ or Notepad. Both conversion processes appear to add  to the beginning of the file.

  9. yihui commented on Jun 27, 2014

    @yihui
    Collaborator

    Can Notepad++ convert the encoding to UTF-8 without the BOM?

    Actually I'm a little surprised that the encoding matters here, since everything is pure ASCII, including &nbsp;.

  10. jrowen commented on Jun 27, 2014

    @jrowen
    Author

    Yes, it does have the Convert to UTF-8 without BOM option, but using it also yields the original Invalid UTF-8 stream error.

  11. yihui commented on Aug 31, 2014

    @yihui
    Collaborator

    @jrowen Although it is unlikely to fix your problem, can you test the current development version of knitr (1.6.15) and see if the error persists?

    install.packages('knitr', repos = c('http://rforge.net', 'http://cran.rstudio.org'),
                     type = 'source')
  12. jrowen commented on Sep 2, 2014

    @jrowen
    Author

    Running into the same error with &nbsp; (actually tested knitr 1.6.16).

    "C:/Program Files/RStudio/bin/pandoc/pandoc" test.utf8.md --to ioslides_presentation.lua --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output C:\Users\jrowen\AppData\Local\Temp\RtmpUFXgXe\ioslides-output1e14bb73b5e.html --data-dir . 
    pandoc.exe: Cannot decode byte '\xa0': Data.Text.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream
    Error: pandoc document conversion failed with error 1
    In addition: Warning message:
    running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" test.utf8.md --to ioslides_presentation.lua --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output C:\Users\jrowen\AppData\Local\Temp\RtmpUFXgXe\ioslides-output1e14bb73b5e.html --data-dir .' had status 1 
    Execution halted
    
  13. yihui commented on Sep 2, 2014

    @yihui
    Collaborator

    Hmm. I really cannot reproduce this problem. I think I have to leave it to other people in the team.

  14. lselzer commented on Sep 18, 2014

    @lselzer

    I tried to reproduce this issue and I couldn't.

  15. yihui commented on Sep 18, 2014

    @yihui
    Collaborator

    @lselzer Thanks for your help!

  16. dmurdoch commented on Apr 17, 2015

    @dmurdoch

    I get a similar error. It appears my minimal example is as follows:

    minimal.Rmd:

    ---
    output: 
      ioslides_presentation
    bibliography: reflist.bib
    nocite: | 
      @rstudio
    ---
    
    ## Slide
    
    Shiny [@shiny]
    

    with reflist.bib:

     @Manual{rstudio,
        title = {RStudio: Integrated development environment for R},
        author = {{RStudio Inc.}},
        year = 2014,
        note = {version 0.99.152},
        url = {http://www.rstudio.org}
     }
    
     @Manual{shiny,
        title = {shiny: Web Application Framework for R},
        author = {{RStudio Inc.}},
        year = {2014},
        url = {http://shiny.rstudio.com}
      }
    

    Running in Windows in a US locale, I get the following output messages when I try to compile:

      |.................................................................| 100%
      ordinary text without R code
    
    
    "C:/Program Files/RStudio/bin/pandoc/pandoc" minimal.utf8.md --to html --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output minimal.html --filter pandoc-citeproc --smart --email-obfuscation none --self-contained --variable transition=0.4 --template "F:\R\svn\R-3-1-branch\library\rmarkdown\rmd\ioslides\default.html" --mathjax --variable "mathjax-url:https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" --variable "ioslides-url=F:\R\svn\R-3-1-branch\library\rmarkdown\rmd\ioslides\ioslides-13.5.1" --bibliography reflist.bib 
    
    
    processing file: minimal.Rmd
    output file: minimal.knit.md
    
    "C:/Program Files/RStudio/bin/pandoc/pandoc" minimal.utf8.md --to ioslides_presentation.lua --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output "C:\Users\murdoch\AppData\Local\Temp\RtmpYf4k13\ioslides-outpute28189a3a46.html" --filter pandoc-citeproc 
    pandoc.exe: Cannot decode byte '\xe2': Data.Text.Internal.Encoding.Fusion.streamUtf8: Invalid UTF-8 stream
    Error: pandoc document conversion failed with error 1
    In addition: Warning message:
    running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" minimal.utf8.md --to ioslides_presentation.lua --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output "C:\Users\murdoch\AppData\Local\Temp\RtmpYf4k13\ioslides-outpute28189a3a46.html" --filter pandoc-citeproc' had status 1 
    Execution halted
    
  17. lselzer commented on Apr 17, 2015

    @lselzer

    I can confirm the issue with ES.AR locale (Spanish_Argentina.1252).
    My guess is that this in a pandoc issue. I tried and got the same error with other computers at work. However, when I raised the issue with the pandoc team they couldn't reproduce it. See
    jgm/pandoc#1634

  18. jjallaire commented on Apr 17, 2015

    @jjallaire
    Member

    @dmurdoch Thanks for reporting this. We've seen issues with UTF-8 characters and ioslides previously but this was related to the use of unicode characters (which pandoc doesn't like when passed through a custom lua markdown renderer like the one we use with ioslides). Your example however appears to only include ascii characters. We'll investigate and hopefully figure out the root cause soon.

  19. jmcphers commented on Apr 20, 2015

    @jmcphers
    Member

    @dmurdoch I spent some time looking into this. It turns out that this is indeed just another manifestation of the non-ASCII character problem; when the citations are injected this content enters the document:

    ———. 2014b. Shiny: Web Application Framework for R. http://shiny.rstudio.com.

    The dashes are en dashes (not hyphens), which are not ASCII, and are translated to this internal Pandoc representation (note the \8212 representation for the en dashes):

    Para [Str "\8212\8212\8212",Str ".",Space,Str "2014",Str "b",Str ".",Space,Emph [Str "Shiny",Str ":",Space,Str "Web",Space,Str "Application",Space,Str "Framework",Space,Str "for",Space,Str "R"]
    

    To the best of my knowledge there's nothing we can do on the rmarkdown side to fix this. We tried a bunch of different input document encodings with and without BOMs; the problem seems not to be in the processing of the input document (which in this case doesn't even contain the offending characters) but in Pandoc's internal handoff from its native encoding format to its Lua interpreter, over which we don't have control.

    As a workaround until the underlying Pandoc issue is fixed (and this does seem to be jgm/pandoc#1634), you could use a CSL that doesn't write en dashes to the stream. For instance, this works for me, via small.csl from here:

    ---
    output: 
      ioslides_presentation:
        self_contained: no
    bibliography: reflist.bib
    csl: small.csl
    nocite: | 
      @rstudio
    ---
    
  20. jmcphers commented on Apr 20, 2015

    @jmcphers
    Member

    Filed an updated bug for Pandoc here: jgm/pandoc#2101

  21. dmurdoch commented on Apr 20, 2015

    @dmurdoch

    On 20/04/2015 4:20 PM, Jonathan wrote:

    @dmurdoch https://github.com/dmurdoch I spent some time looking into
    this. It turns out that this is indeed just another manifestation of the
    non-ASCII character problem; when the citations are injected this
    content enters the document:

    Thanks, this is really helpful. I'm on the road right now and can't
    check that it works, but it certainly looks like it should.

    Duncan Murdoch

    ———. 2014b. Shiny: Web Application Framework for R.
    http://shiny.rstudio.com.

    The dashes are en dashes (not hyphens), which are not ASCII, and are
    translated to this internal Pandoc representation (note the |\8212|
    representation for the en dashes):

    |Para [Str "\8212\8212\8212",Str ".",Space,Str "2014",Str "b",Str ".",Space,Emph [Str "Shiny",Str ":",Space,Str "Web",Space,Str "Application",Space,Str "Framework",Space,Str "for",Space,Str "R"]
    |

    To the best of my knowledge there's nothing we can do on the rmarkdown
    side to fix this. We tried a bunch of different input document encodings
    with and without BOMs; the problem seems not to be in the processing of
    the input document (which in this case doesn't even contain the
    offending characters) but in Pandoc's internal handoff from its native
    encoding format to its Lua interpreter, over which we don't have control.

    As a workaround until the underlying Pandoc issue is fixed (and this
    does seem to be jgm/pandoc#1634
    jgm/pandoc#1634), you could use a CSL that
    doesn't write en dashes to the stream. For instance, this works for me,
    via small.csl from here https://github.com/citation-style-language/styles:

    |---
    output:
    ioslides_presentation:
    self_contained: no
    bibliography: reflist.bib
    csl: small.csl
    nocite: |

    @rstudio

    |
    |

    —
    Reply to this email directly or view it on GitHub
    #134 (comment).

  22. github-actions commented on Nov 3, 2020

    @github-actions

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

  23. locked as resolved and limited conversation to collaborators on Nov 3, 2020
  24. added a commit that references this issue on Apr 28, 2023
    689130c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions