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

kjhealy opened this issue Jun 14, 2021 · 0 comments

Error: highlight call unsuccessful #379

kjhealy opened this issue Jun 14, 2021 · 0 comments


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:
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")

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",
    " -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.")
  # }

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:
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 
file(con, "r") 
base::readLines(path, n = n, encoding = "UTF-8", warn = FALSE) at utils-io.R#11
read_lines(reprex_file) at utils-io.R#234
ifelse( | is.matrix(content), "table", 
render_object(content, object_type, breaks, .dots) 
write_nix(content, object_type, breaks, eos, return_new, con, 
chosen_write_clip(content, object_type, breaks, eos, return_new, 
clipr::write_clip(read_lines(reprex_file)) at utils-io.R#234
expose_reprex_output(reprex_file, rtf = (venue == "rtf")) at reprex_impl.R#101
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
reprex(..., venue = "rtf") at venues.R#23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

1 participant