Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nviraj opened this issue Sep 5, 2023 · 2 comments

Comments

@nviraj
Copy link

nviraj commented Sep 5, 2023

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
@jennybc
Copy link
Member

jennybc commented Nov 24, 2023

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.

@jennybc
Copy link
Member

jennybc commented Nov 24, 2023

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.

@jennybc jennybc closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants