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

[Bug]: chunk fails to run on context: setup #114

Closed
jimjam-slam opened this issue Dec 2, 2023 · 8 comments · Fixed by #120
Closed

[Bug]: chunk fails to run on context: setup #114

jimjam-slam opened this issue Dec 2, 2023 · 8 comments · Fixed by #120
Labels
s: confirmed Issue was confirmed to exist s: duplicate This issue or pull request already exists t: bug Something isn't working
Milestone

Comments

@jimjam-slam
Copy link

Bug description

This could potentially be related to #105 (although I'm not in a position to say for sure), but in the following reprex, running the second chunk fails with Error: object 'bad_mtcars' not found when the first chunk has context: setup.

If you remove context: setup from the first chunk and then run the two sequentially, the second runs as expected (printing the data frame).

---
title: "Test"
engine: knitr
filters:
  - webr
webr:
  packages: ["dplyr", "tibble", "crayon"]
format:
  html: default
---

This first chunk creates a dataset derived from `mtcars` for demonstration purposes:

```{webr-r}
#| label: spike-data
#| context: setup
mtcars |>
  tibble::rownames_to_column(var = "car") |>
  tibble::as_tibble() |>
  dplyr::select(car, cyl, disp, wt) |>
  dplyr::mutate(wt = dplyr::case_when(
    wt < 2 ~ -wt,
    TRUE ~ wt)) ->
bad_mtcars
```

Then we print it to see how it looks:

```{webr-r}
#| label: spike-data
bad_mtcars
```

Steps to reproduce

  1. Render reprex doc as is and run chunk; note failure
  2. Remove #| context: setup from first chunk
  3. Re-render and run both chunks

Your environment

IDE: VSCode
OS: macOS 14.0

Here's the session info inside WebR (I was a little surprised that tibble and dplyr were loaded even if I didn't run either chunk—does putting them in the YAML load them too?)

R version 4.3.0 (2023-04-21)
Platform: wasm32-unknown-emscripten (32-bit)
Running under: emscripten

Matrix products: default
BLAS:   unknown 


locale:
[1] en_US.UTF-8 C           en_US.UTF-8 en_US.UTF-8 en_US.UTF-8 C          

time zone: Australia/Melbourne
tzcode source: internal

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

other attached packages:
[1] crayon_1.5.2 tibble_3.2.1 dplyr_1.1.3 

loaded via a namespace (and not attached):
 [1] utf8_1.2.4       R6_2.5.1         tidyselect_1.2.0 webr_0.2.2      
 [5] magrittr_2.0.3   glue_1.6.2       pkgconfig_2.0.3  generics_0.1.3  
 [9] lifecycle_1.0.4  cli_3.6.1        fansi_1.0.5      vctrs_0.6.4.9000
[13] tools_4.3.0      pillar_1.9.0     rlang_1.1.2 

Quarto check output

Quarto 99.9.9
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.9: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      Path: /Users/rensa/Code/quarto-cli/package/dist/bin

Check file:///Users/rensa/Code/quarto-cli/src/resources/vendor/deno-land/x/puppeteer@9-0-2/mod.ts
[✓] Checking tools....................OK
      TinyTeX: (external install)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/rensa/Library/TinyTeX/bin/universal-darwin
      Version: 2021

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.9.7 (Conda)
      Path: /Users/rensa/miniforge3/bin/python
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with conda install jupyter

[✓] Checking R installation...........OK
      Version: 4.2.1
      Path: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources
      LibPaths:
        - /Users/rensa/Library/R/arm64/4.2/library
        - /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
      knitr: 1.42
      rmarkdown: 2.21

[✓] Checking Knitr engine render......OK
@coatless
Copy link
Owner

coatless commented Dec 3, 2023

This is a duplicate of #105 and #88 on the notion of the packages key not aligning nicely with the non-interactive cells.

(I was a little surprised that tibble and dplyr were loaded even if I didn't run either chunk—does putting them in the YAML load them too?)

From v0.3.8 onward, we added a new feature to autoload R packages specified in packages, e.g. library(packages[i]), prior to the document being modifiable.

https://quarto-webr.thecoatlessprofessor.com/qwebr-meta-options.html#autoload-packages

@coatless coatless added t: bug Something isn't working s: duplicate This issue or pull request already exists s: confirmed Issue was confirmed to exist labels Dec 3, 2023
@coatless
Copy link
Owner

@jimjam-slam I reworked a bit on the non-interactive cells in #120. They should now respect the packages key completely.

demo-non-interactive-cells-paired-with-interactive

Care to give it a go and let me know if something else is amiss?

quarto add coatless/quarto-webr@cell-state-manager

@jimjam-slam
Copy link
Author

I'll give it a spin today!

@coatless
Copy link
Owner

@jimjam-slam thanks; please make sure to re-pull if you already grabbed a copy of dev as I pushed one more fix onto that branch.

@jimjam-slam
Copy link
Author

Can confirm it's working great when I pull the cell-state-manager branch! Thanks very much—I'll be keen to see this hit main!

@coatless
Copy link
Owner

coatless commented Jan 17, 2024

@jimjam-slam excellent; I appreciate it!

After I clean up how non-interactive cells are displayed visually, this branch will likely hit main in the next 24 hours.

Main changes for the visualization relate to state changes for non-interactives, e.g. loading webr ... , hidden cells executing, processing this cell, deleting status if setup.

Still have a few more tweaks related to introducing a new toolbar above interactive cells. c.f. #91 .

@jimjam-slam
Copy link
Author

Nice! I wrote up a blog post while exploring the new quarto-webr functionality; I'll put it out once I get to test everything together!

@coatless
Copy link
Owner

Merged in.

The status visualization changes that were committed in can be seen here:

demo-quarto-webr-non-interactive-areas

I'll probably regress showing a visual indicator for the setup context in the document.

@coatless coatless added this to the 4.0 milestone May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: confirmed Issue was confirmed to exist s: duplicate This issue or pull request already exists t: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants