2

In the past, the html output from str_view() could be properly rendered in pdf slides, given that the webshot package was installed (see also this answer). However, this no longer works.

The following Rmd file should produce a title slide and a slide showing a regex example:

---
title: "Regex"
output: beamer_presentation
---

```{r setup, include=FALSE}
library(stringr)
```

## `str_view`

```{r regex1}
str_view(c("abc", "bcd", "cde"), "bc", html = TRUE)
```

If only the webshot package, but not webshot2, is installed, I get the following error on knitting:

Error:
! webshot.js returned failure value: 1
Backtrace:
  1. rmarkdown::render(...)
  2. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  3. knitr:::process_file(text, output)
  7. knitr:::process_group.block(group)
  8. knitr:::call_block(x)
     ...
 19. knitr (local) value_fun(ev$value, ev$visible)
 20. knitr (local) fun(x, options = options)
 22. knitr::knit_print(x, ...)
 23. knitr:::html_screenshot(x)
 26. webshot (local) `<fn>`(...)
Execution halted

Calling webshot::is_phantomjs_installed() returns TRUE, so PhantomJS is installed.

If I install webshot2, knitting works without error, but the html-output of str_view() is not shown:

enter image description here

The expected output that could be created in the past would look something like this (recreated with an image manipulation program):

enter image description here

What is the problem here? And is there still a way to get this to work?

(I am aware that I could use the text output from str_view() without html = TRUE, but I would prefer the html output.)

I am running this on Ubuntu 22.04.2 using the following versions:

  • R 4.3.1
  • Pandoc 3.1.1 (the version that comes with RStudio)
  • webshot 0.5.5
  • webshot2 0.1.0
  • rmarkdown 2.23
  • knitr 1.43
  • stringr 1.5.0
Stibu
  • 15,166
  • 6
  • 57
  • 71
  • can you include the version of webshot, stringr etc you are using? Because the code works for me – Mark Aug 10 '23 at 03:07
  • @Mark Does it work with webshot or webshot2? And you can see the htmI output? I have added the versions to the question. – Stibu Aug 11 '23 at 06:47
  • I'm not sure if it's actually using either, as (from what I understand) webshot and webshot2 create screenshots, and the output from knitting the file has highlightable text, which generally isn't the case with screenshots – Mark Aug 11 '23 at 06:53
  • @mark That's an excellent observation: also in my old slides, the text can be marked and copied. But on the other hand, I get an error message from webshot, when I knit with only webshot installed. Which of the two (webshot, webshot2) do you have installed? – Stibu Aug 11 '23 at 07:03
  • I installed both – Mark Aug 11 '23 at 07:04
  • what happens when you try to run the code chunk without knitting? – Mark Aug 11 '23 at 07:04
  • https://i.stack.imgur.com/zgyTb.png after running the code, I get this – Mark Aug 11 '23 at 07:04
  • @Mark Me too, running `str_view()` in RStudio shows the rendered html in the Viewer as expected. – Stibu Aug 11 '23 at 07:54
  • interesting/how odd! So it would appear that you are able to generate correct html. Okay, another test - what if you try knitting the html to another format? e.g. instead of making a beamer_presentation, knit to a pdf_document – Mark Aug 11 '23 at 08:31
  • @Mark Thanks for the new idea. Unfortunately, with pdf_document the result is the same: the code is shown, the output is empty. It really seems that this is a problem outside of R/knitr/rmarkdown. By the way, what system are you using? Mine is Ubuntu 22.04. – Stibu Aug 11 '23 at 08:54
  • I'm using Mac, but I have a Windows PC I could try it out on. Could potentially download Ubuntu as well if needs be – Mark Aug 11 '23 at 09:28
  • @Mark Well, that seems a bit too much effort from your side. I also checked html_document and this works. Thanks for your help so far. I probably need someone who can reproduce the problem and solve it. I am really quite clueless what else I could try. – Stibu Aug 11 '23 at 09:29
  • the one thing I can think of that could potentially give some leads is manually knitting the file. From what I understand, it's a multi-step process, and if you can figure out which part of it is not working, it should help get closer to the nub of the issue – Mark Aug 11 '23 at 09:34
  • I sometimes use VS Code, which I'm fairly sure uses it's own R installation, at least on Mac. You could try using that, and then see if you still get the same result. If you do, then you can rule out the R distribution or any of the individual packages you have. – Mark Aug 11 '23 at 09:37

0 Answers0