rr-markdownmaxima

Conditional execution of Maxima chunks in RMarkdown


I have a file which is meant to dynamically create exercises. In this file I use R for statistical calculations and random number generation and Maxima as CAS through the R library rim, using the following basic setup.

knitr::opts_chunk$set(echo = TRUE)
options(digits=2)
library(xtable)
library(rim)
library(reticulate)  ## better Python in R
maxima.options(engine.format = "latex", 
           engine.label = TRUE,
           inline.format = "latex", 
           inline.label = FALSE)

I then want to switch between different functions for an exercise by randomly generating a switch through

switch1<-FALSE;switch2<-FALSE
exercise<-sample(1:2,1)
switch(exercise,
       switch1<-TRUE,
       switch2<-TRUE)

print(c(switch1,switch2)) # check that only one is TRUE and the other FALSE

Then I hand this logical switch to the eval option of the respective Maxima chunk.

```{maxima eval=switch1,echo=FALSE}
f:1/(x-4)+1/(y+2)+4^2*x+4*y-3;
```{maxima eval=switch2,echo=FALSE}
f:3/(2*x+1)-1/y+6*x-4*y+2;

However, both statements are evaluated, as if I did not set a switch, even though one is FALSE. When I use a chunk with R as the programming language, the switching works - only the maxima chunk does not work.

Could anyone help me solve the problem of properly switching on the Maxima chunks.


Solution

  • UPDATE

    Thanks for opening the issue!

    This was a rim specific problem: Basically, chunk option eval was ignored before version0.5.1. See examples on the current (0.6.3) vignette page.

    Your case should work as expected with the latest version.