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

Hashpipe-style chunk options cause learnr to crash #795

Closed
jimjam-slam opened this issue Aug 22, 2023 · 1 comment · Fixed by #796
Closed

Hashpipe-style chunk options cause learnr to crash #795

jimjam-slam opened this issue Aug 22, 2023 · 1 comment · Fixed by #796

Comments

@jimjam-slam
Copy link

System details

Output of sessioninfo::session_info()():

R version 4.2.3 (2023-03-15)
Platform: aarch64-unknown-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/aarch64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/aarch64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.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  
[7] base     

other attached packages:
[1] learnr_0.11.4.9000 shiny_1.7.4       

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.10       compiler_4.2.3    bslib_0.4.2      
 [4] later_1.3.0       jquerylib_0.1.4   tools_4.2.3      
 [7] digest_0.6.31     memoise_2.0.1     jsonlite_1.8.4   
[10] evaluate_0.20     lifecycle_1.0.3   checkmate_2.2.0  
[13] rlang_1.1.0       cli_3.6.0         rstudioapi_0.14  
[16] parallel_4.2.3    yaml_2.3.7        xfun_0.40        
[19] fastmap_1.1.1     withr_2.5.0       stringr_1.5.0    
[22] knitr_1.42        rappdirs_0.3.3    htmlwidgets_1.6.1
[25] sass_0.4.5        vctrs_0.6.3       systemfonts_1.0.4
[28] rprojroot_2.0.3   glue_1.6.2        R6_2.5.1         
[31] rmarkdown_2.20    magrittr_2.0.3    backports_1.4.1  
[34] promises_1.2.0.1  ellipsis_0.3.2    htmltools_0.5.4  
[37] mime_0.12         xtable_1.8-4      httpuv_1.6.9     
[40] renv_1.0.2.9000   stringi_1.7.12    cachem_1.0.7     
[43] crayon_1.5.2 

Example application or steps to reproduce the problem

Works:

---
title: "Hello, Tutorial!"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
library(learnr)
```

This code computes the answer to one plus one,
change it so it computes two plus two:

```{r addition, exercise=TRUE}
1 + 1
```

Does not work:

---
title: "Hello, Tutorial!"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{r}
#| label: setup
#| include: FALSE
library(learnr)
```

This code computes the answer to one plus one,
change it so it computes two plus two:

```{r}
#| label: addition
#| exercise: TRUE
1 + 1
```

Also does not work:

---
title: "Hello, Tutorial!"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{r}
#| setup, include=FALSE
library(learnr)
```

This code computes the answer to one plus one,
change it so it computes two plus two:

```{r}
#| addition, exercise=TRUE
1 + 1
```

Describe the problem in detail

I generally use Quarto these days, and I'm afraid I've gotten a little too used to the hashpipe-style YAML chunk options it offers! 😅

When trying out the simple {learnr} demo, I noticed that it works great as is, but if I try to modify it to use hashpipe-style chunk options (using either the YAML syntax or the comma-separated one, {learnr} crashes as soon as a user-runnable code chunk is executed (which, depending on how the document is structured, is either on first run or when a code window's Run button is pushed).

@gadenbuie
Copy link
Member

Thanks for the report @jimjam-slam! There's something unusual happening with knitr when #| label: addition is used instead of {r addition}. learnr's code could be more defensive against these differences (I'll have a PR up shortly) but I think it's also an inconsistency worth fixing in knitr (I'll file a bug report shortly as well).

For now, I'd recommend declaring the chunk label in the chunk header. This is working for me:

---
title: "Hello, Tutorial!"
output: learnr::tutorial
runtime: shiny_prerendered
---

```{r}
#| label: setup
#| include: FALSE
library(learnr)
```

This code computes the answer to one plus one,
change it so it computes two plus two:

```{r}
#| label: addition
#| exercise: TRUE
1 + 1
```

As is this pattern:

```{r addition}
#| exercise=TRUE
1 + 1
```

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

Successfully merging a pull request may close this issue.

2 participants