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

autodep regression by #2321 #2344

Open
3 tasks done
heavywatal opened this issue May 28, 2024 · 8 comments · May be fixed by #2377
Open
3 tasks done

autodep regression by #2321 #2344

heavywatal opened this issue May 28, 2024 · 8 comments · May be fixed by #2377
Assignees

Comments

@heavywatal
Copy link

The option autodep=TRUE does not work since #2321 even with the simplest example as follows:

```{r, setup}
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(autodep = TRUE)
```

```{r, src}
x = 1
```

```{r, dst}
y = 10 * x
y
```

Modifying x in src chunk should invalidate the cache of the dependent chunk dst, but is ignored in the latest version. I have tried different versions with pak::pkg_install("yihui/knitr"). Here are the results:

> xfun::session_info('knitr')
R version 4.4.0 (2024-04-24)
Platform: x86_64-apple-darwin20
Running under: macOS Sonoma 14.5

Locale: C / en_US.UTF-8 / C / C / C / C

Package version:
  evaluate_0.23   grDevices_4.4.0 graphics_4.4.0  highr_0.11
  knitr_1.46.5    methods_4.4.0   stats_4.4.0     tools_4.4.0
  utils_4.4.0     xfun_0.44       yaml_2.3.8

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@heavywatal
Copy link
Author

FYI, adding cache-globals does not help invalidation.

```{r, dst2}
#| cache-globals:
#|   - x
z = 100 * x
z
```

@yihui
Copy link
Owner

yihui commented May 28, 2024

@knokknok @atusy Could you take a look? Thanks!

@atusy
Copy link
Collaborator

atusy commented May 29, 2024

I will

@knokknok
Copy link
Contributor

Don't you need an initial dep_auto() to set-up the system?

@atusy
Copy link
Collaborator

atusy commented Oct 9, 2024

Sorry for being silent.
I take a look at this issue.

@heavywatal
Copy link
Author

Thank you @atusy. Here is my current understanding:

  1. Both autodep = TRUE and knitr::dep_auto() are required in knitr>=v1.46.
  2. knitr::dep_auto() has long been there, but I did not know (or just forgot) its existence before @knokknok's suggestion because it is not documented in https://yihui.org/knitr/options/ and autodep = TRUE worked fine without it in knitr<=v1.45.
  3. knitr::dep_auto() emits warning when it is executed for the first time:
    Warning in parse_objects(paths[1L]): file .cache/__objects not found
    Warning in parse_objects(paths[2L]): file .cache/__globals not found
    

Now my setup chunk looks like this:

#| cache: false
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(autodep = TRUE)
if (dir.exists(knitr::opts_chunk$get("cache.path"))) knitr::dep_auto()  # NEW!

It seems a little redundant. How about modifying knitr::dep_auto()?

  • to set autodep = TRUE (and cache = TRUE) internally
  • not to emit warning when __objects and __globals are not found

@atusy
Copy link
Collaborator

atusy commented Oct 10, 2024

@heavywatal

Thank you, too. Your understanding is right.

I am trying to automate knitr::dep_auto(labels = all_labels()).

to set autodep = TRUE (and cache = TRUE) internally

I am against this because I remember a book (R Markdown Cookbook?) recommends cache = TRUE per chunks, not globally.

atusy added a commit to atusy/knitr that referenced this issue Oct 16, 2024
atusy added a commit to atusy/knitr that referenced this issue Oct 16, 2024
@atusy
Copy link
Collaborator

atusy commented Oct 16, 2024

I partially solved the issue by automatically calling dep_auto(labels = all_labels()) when the chunk option autodep = TRUE is found for the first time.

However, this implementation does not work well when there is a child document.
I will try fix it, too.

atusy added a commit to atusy/knitr that referenced this issue Oct 17, 2024
atusy added a commit to atusy/knitr that referenced this issue Oct 17, 2024
atusy added a commit to atusy/knitr that referenced this issue Oct 17, 2024
atusy added a commit to atusy/knitr that referenced this issue Oct 17, 2024
atusy added a commit to atusy/knitr that referenced this issue Oct 17, 2024
@atusy atusy linked a pull request Oct 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants