tidyverse / reprex

Render bits of R code for sharing, e.g., on GitHub or StackOverflow.

Home Page:https://reprex.tidyverse.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to generate a reprex due to possibly clipboard or file connection issue

nviraj opened this issue · comments

Hi,
I am unable to generate a reprex using 2.0.2. Apologies for not being able to follow your issues template. This appears to be the case for both the IDE add-in as well as Console.

Here is the error stack:

> reprex::reprex(input = "reprex - v2.R", venue = "gh", session_info = TRUE)
✔ Preparing reprex as `.R` file:
  reprex - v2_reprex.RRendering reprex...
Error in `reprex_render()`:
! This reprex appears to crash R. Call `reprex()` again with `std_out_err = TRUE` to get more info.
Run `rlang::last_trace()` to see where the error occurred.
> reprex::reprex(input = "reprex - v2.R", venue = "gh", session_info = TRUE, std_out_err = TRUE)
! Oops, file already exists:
  reprex - v2_reprex.R
Carry on and overwrite it?
1: yes
2: no

Selection: 1Preparing reprex as `.R` file:
  reprex - v2_reprex.RRendering reprex...Writing reprex file:
  reprex - v2_reprex.mdReprex output is on the clipboard.
Warning message:
In utils::writeClipboard(rendered_content, format = format) :
  unable to open the clipboard

Here is the content of std_out_err.text

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'D:/Root/Personal/WorkSpace/pool_issue/reprex - v2_reprex.spin.Rmd': No such file or directory

I think the short answer is that the spaces in the filename are a problem (reprex - v2.R). That's not good and should be looked into, but my advice to get you unstuck now is to not have spaces in the filename. That's sort of a good rule to live by anyway, but I understand that it's not something that one always has control over.

I have tracked this down to the pre_knit() function in reprex's custom output format:

# I don't know why the pre_knit hook operates on the **original** input
# instead of the to-be-knitted (post-spinning) input, but I need to
# operate on the latter. So I brute force the correct path.
# This is a no-op if input starts as `.Rmd`.

Apparently we have to do some hack and that is not working well when the original input filename has spaces. In the debugger, I can see that knitr has actually replaced spaces with - and, presumably, reverses that fix later. If I do rmarkdown::render("spaces are tricky.R", "reprex::reprex_document") and set a breakpoint in pre_knit(), the file system looks like so:

  -rw-r--r--@   1 jenny  staff      11 24 Nov 07:58 spaces are tricky.R
  -rw-r--r--@   1 jenny  staff      11 24 Nov 08:05 spaces-are-tricky.R
  -rw-r--r--@   1 jenny  staff  623379 24 Nov 07:58 spaces-are-tricky.html
  -rw-r--r--@   1 jenny  staff      40 24 Nov 08:01 spaces-are-tricky.md
  -rw-r--r--@   1 jenny  staff      11 24 Nov 08:05 spaces-are-tricky.spin.R
  -rw-r--r--@   1 jenny  staff      95 24 Nov 08:05 spaces-are-tricky.spin.Rmd

So this is the problem. I've left the notes above for possible future investigation, but for now this is a #wontfix. I think it's pretty rare to use reprex with an input file and, within that narrow use case, my recommendation is to avoid have spaces in the filepath.