repr icon indicating copy to clipboard operation
repr copied to clipboard

`repr_html` not working under R 4.1.1

Open renkun-ken opened this issue 5 years ago • 7 comments

Once I upgrade to R 4.1.1, repr_html() no longer works:

hfile <- utils::help("get")
repr::repr_html(hfile)
Error in seq_len(head.end.idx) : 
  argument must be coercible to non-negative integer
In addition: Warning message:
In seq_len(head.end.idx) : first element used of 'length.out' argument
Backtrace:
1: repr_help_files_with_topic_generic(obj, Rd2HTML)
2: repr_html.help_files_with_topic(hfile)
3: repr::repr_html(hfile)

Related: https://github.com/REditorSupport/languageserver/issues/468

renkun-ken avatar Aug 12 '21 05:08 renkun-ken

Looks like

https://github.com/IRkernel/repr/blob/7f27d6a359c65e52ddee52a866c6a9f1999947f3/R/repr_help_files_with_topic.r#L51-L53

no longer applies to the HTML files of R 4.1.1 where it should match these two lines instead.

[5]:"</head><body><div class=\"container\">"
[167]:"</div></body></html>"

Looks like search for the line that contains or startsWith </head><body> and endsWith </body></html> should be enough.

renkun-ken avatar Aug 12 '21 05:08 renkun-ken

For me, when I use the ? operator or the function utils::help to pull the doc pages, it returns unrendered latex, rather than html.

library( tidyverse )
my_doc_text <- utils::help( "str_split" )
Screen Shot 2021-08-17 at 3 10 14 PM

When I try to render it using IRdisplay::display_latex( my_doc_text ) I get an error with the following backtrace:

Error: No method asJSON S3 class: help_files_with_topic
Traceback:

1. IRdisplay::display_latex(my_doc_text)
2. display_raw("text/latex", FALSE, data, file)
3. publish_mimebundle(data, metadata)
4. getOption("jupyter.base_display_func")(data, metadata)
5. send_response("display_data", current_request, "iopub", list(data = data, 
 .     metadata = metadata))
6. zmq.send.multipart(socket, msg_to_wire(msg), serialize = FALSE)
7. msg_to_wire(msg)
8. charToRaw(toJSON(msg$content, auto_unbox = TRUE))
9. toJSON(msg$content, auto_unbox = TRUE)
10. asJSON(x, dataframe = dataframe, Date = Date, POSIXt = POSIXt, 
  .     factor = factor, complex = complex, raw = raw, matrix = matrix, 
  .     auto_unbox = auto_unbox, digits = digits, na = na, null = null, 
  .     force = force, indent = indent, ...)
11. asJSON(x, dataframe = dataframe, Date = Date, POSIXt = POSIXt, 
  .     factor = factor, complex = complex, raw = raw, matrix = matrix, 
  .     auto_unbox = auto_unbox, digits = digits, na = na, null = null, 
  .     force = force, indent = indent, ...)
12. .local(x, ...)
13. vapply(x, asJSON, character(1), na = na, auto_unbox = auto_unbox, 
  .     indent = indent + 2L, no_dots = no_dots, ...)
14. FUN(X[[i]], ...)
15. FUN(X[[i]], ...)
16. .local(x, ...)
17. vapply(x, asJSON, character(1), na = na, auto_unbox = auto_unbox, 
  .     indent = indent + 2L, no_dots = no_dots, ...)
18. FUN(X[[i]], ...)
19. FUN(X[[i]], ...)
20. .local(x, ...)
21. stop("No method asJSON S3 class: ", class(x))
22. base::stop(..., call. = FALSE)

colettace avatar Aug 17 '21 19:08 colettace

same issue here, I can confirm that the proposed PR https://github.com/IRkernel/repr/pull/144 fixes the issue.

rvalieris avatar Aug 29 '21 21:08 rvalieris

Getting the same issue when running ?help based commands.

?mean
Warning message in seq_len(head.end.idx):
“first element used of 'length.out' argument”
ERROR while rich displaying an object: Error in seq_len(head.end.idx): argument must be coercible to non-negative integer

Traceback:
1. FUN(X[[i]], ...)
2. tryCatch(withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler), error = outer_handler)
3. tryCatchList(expr, classes, parentenv, handlers)
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. doTryCatch(return(expr), name, parentenv, handler)
6. withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler)
7. repr::mime2repr[[mime]](obj)
8. repr_html.help_files_with_topic(obj)
9. repr_help_files_with_topic_generic(obj, Rd2HTML)
sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS

Matrix products: default
BLAS/LAPACK: /opt/conda/lib/libopenblasp-r0.3.17.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] fansi_0.5.0     digest_0.6.28   utf8_1.2.2      crayon_1.4.1   
 [5] IRdisplay_1.0   repr_1.1.3      lifecycle_1.0.1 jsonlite_1.7.2 
 [9] evaluate_0.14   pillar_1.6.3    rlang_0.4.11    uuid_0.1-4     
[13] vctrs_0.3.8     ellipsis_0.3.2  IRkernel_1.2    tools_4.1.1    
[17] fastmap_1.1.0   compiler_4.1.1  base64enc_0.1-3 pbdZMQ_0.3-5   
[21] htmltools_0.5.2
IPython             7.27.0
jupyter_client      7.0.2
jupyter_core        4.7.1
jupyterlab          3.0.14
notebook            6.3.0
-----
Python 3.8.10 | packaged by conda-forge | (default, May 11 2021, 07:01:05) [GCC 9.3.0]
Linux-4.19.104-microsoft-standard-x86_64-with-glibc2.10

MLKaufman avatar Oct 14 '21 17:10 MLKaufman

I still getting the same issue under R4.1.2 in Jupyterlab 3.2.2.

kaufmanno avatar Nov 07 '21 14:11 kaufmanno

Why closed?

CholoTook avatar Nov 15 '21 11:11 CholoTook

See the close event:

grafik

There’s a link you can click which tells you what the fix was.

flying-sheep avatar Nov 15 '21 12:11 flying-sheep