r-lib / downlit

Syntax Highlighting and Automatic Linking
https://downlit.r-lib.org
Other
90 stars 22 forks source link

evaluation nested too deeply when looking topic for base package #152

Closed cderv closed 2 years ago

cderv commented 2 years ago

This is quite specific but I figured it is interested to report

Here is a minimal reprex for the issue I found after last downlit update. (it can be even simplify more)

system <- function(...) processx::run(...)
downlit:::href_topic_remote("system", "base")
#> Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

unique <- function(...) dplyr::distinct(...)
downlit:::href_topic_remote("unique", "base")
#> Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

Quite specific because it happens when there is a function name in workspace same as one in base environment, and href_topic_remote is called. In this specific case:

  1. href_topic_remote() will call href_topic_reexported()
  2. and href_topic_reexported() will call href_topic_remote()

Traceback subset

(...)
7: href_topic_remote(topic, ex_package)
6: href_topic_reexported(topic, package)
5: href_topic_remote(topic, ex_package)
4: href_topic_reexported(topic, package)
3: href_topic_remote(topic, ex_package)
2: href_topic_reexported(topic, package)
1: downlit:::href_topic_remote("system", "base")

This happened in a bookdown with bs4_book() as downlit::downlit_html_path() is used in bs4_chapter_tweak() function.

The real case usage for which this happened is

```{r include=FALSE}
system = function(...) cat(base::system(..., intern = TRUE), sep = '\n')
system('pdflatex --version')


`system` is overwritten in the Rmd so that it shows as `system()` in the code output, but the result is better formatted for output. This can be surely modified, but this is interesting to know that this is what is causing the issue with latest **downlit**. 
hadley commented 2 years ago

Have you tried the latest dev version? @DavisVaughan also reported this so I pushed a quick fix.

cderv commented 2 years ago

I think I had. But maybe not then.... Got mixed up somehow.

Updating to dev version indeed fix the issue as there is not more error. I got NA instead.

system <- function(...) processx::run(...)
downlit:::href_topic_remote("system", "base")
#> [1] NA
unique <- function(...) dplyr::distinct(...)
downlit:::href_topic_remote("unique", "base")
#> [1] NA

with

downlit     0.4.1.9000 2022-07-04 [1] Github (r-lib/downlit@128f49a)

Sorry for the noise. Should have looked at more than just the NEWS.md. Fix is here; 3a58c5e7638d2b91a336a85948dca6957fd71447

hadley commented 2 years ago

Hmmm you shouldn't be getting NAs though