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

Error: highlight call unsuccessful #379

Closed
kjhealy opened this issue Jun 14, 2021 · 0 comments
Closed

Error: highlight call unsuccessful #379

kjhealy opened this issue Jun 14, 2021 · 0 comments

Comments

@kjhealy
Copy link

kjhealy commented Jun 14, 2021

I'm trying to produce RTF reprexes / prexes on R 4.1 with highlight installed from homebrew. I'm running macOS 11.4. The behavior is the same on the development and CRAN versions of reprex().

With both reprex_rtf() and prex_rtf(), I get the following error:

highlight: Could not read input file:
/Users/kjhealy/Documents/courses/dataviz_0621/awful-dog_reprex_r_r.R
Error: `highlight` call unsuccessful.
Backtrace:1. └─reprex:::prex_rtf()
 2.   └─reprex:::prex(..., venue = "rtf")
 3.     └─reprex:::reprex_impl(...)
 4.       └─reprex:::reprex_render_impl(...)
 5.         └─reprex:::pp_highlight(pp_md_to_r(md_file, comment = comment))
 6.           └─reprex:::reprex_highlight(r_file_rendered(input), rtf_file)

So the problem is with the reprex_highlight() call.

I have the highlight utility installed, and R can see it:

# > Sys.which("highlight")
                 highlight 
"/usr/local/bin/highlight" 

The various reprex random-name-output files are produced as expected in the working directory. After a failed prex_rtf() or reprex_rtf() call, say one that produces files named awful-dog_reprex.R etc, at the terminal I can do

highlight -i awful-dog_reprex.R --out-format rtf --no-trailing-nl --encoding=UTF-8 --style "moe" --font 'IBMPlexMono-Text' --font-size 36 | pbcopy

This produces the expected result (i.e. a rendered RTF of the R file in the clipboard, which I can paste into Keynote). There's no additional output (warning, errors, messages, etc) from highlight that would indicate any problems.

I saw #331 reported something similar but that was on Windows rather than macOS and initially Sys.which() wasn't working in that case, whereas here it is. However, the problem does seems to be happening in the same functions that were changed as a result of #345, which fixed #331. So maybe some additional issue was introduced?

I cloned the repo and recompiled the package so that reprex_highlight() would expose a little more of what was happening just by commenting out its abort() condition.

reprex_highlight <- function(rout_file, reprex_file, arg_string = NULL) {
  arg_string <- arg_string %||% highlight_args()
  cmd <- paste0(
    "highlight ",
    " -i ", rout_file,
    " --out-format=rtf --no-trailing-nl --encoding=UTF-8",
    arg_string,
    " -o ", reprex_file
  )
  if (is_windows()) {
    res <- shell(cmd)
  } else {
    res <- system(cmd)
  }
### Commented out the abort condition
  # if (res > 0) {
  #   abort("`highlight` call unsuccessful.")
  # }
  res
}

Running the reprex again produced this traceback. It looks like can't open the reprex_file it wants:

> reprex_rtf()
ℹ Rendering reprex...
highlight: Could not read input file:
/private/var/folders/0c/hc2fp3hn3sl1r1pv973q5dsc0000gn/T/Rtmpq3vDlV/reprex-79a824c77628-pure-tayra/pure-tayra_reprex_r_r.R
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
 
 Error in file(con, "r") : cannot open the connection 
14.
file(con, "r") 
13.
base::readLines(path, n = n, encoding = "UTF-8", warn = FALSE) at utils-io.R#11
12.
read_lines(reprex_file) at utils-io.R#234
11.
is.data.frame(content) 
10.
ifelse(is.data.frame(content) | is.matrix(content), "table", 
    "character") 
9.
eval_object(content) 
8.
render_object(content, object_type, breaks, .dots) 
7.
write_nix(content, object_type, breaks, eos, return_new, con, 
    .dots) 
6.
chosen_write_clip(content, object_type, breaks, eos, return_new, 
    ...) 
5.
clipr::write_clip(read_lines(reprex_file)) at utils-io.R#234
4.
expose_reprex_output(reprex_file, rtf = (venue == "rtf")) at reprex_impl.R#101
3.
reprex_impl(x_expr = substitute(x), input = input, wd = wd, venue = venue, 
    render = render, new_session = TRUE, advertise = advertise, 
    session_info = session_info, style = style, html_preview = html_preview, 
    comment = comment, tidyverse_quiet = tidyverse_quiet, std_out_err = std_out_err,  ... at reprex.R#272
2.
reprex(..., venue = "rtf") at venues.R#23
1.
reprex_rtf() 

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

1 participant