0

This is my MWE for a .Rmd file:

    ---
output:
  html_document: default
  pdf_document: default
editor_options:
  chunk_output_type: console
---

Uma vez que a `r vd` é medida numa escala `r ifelse(class_vd[1]=="ordered", "ordinal, o teste a usar é o Wilcoxon-Mann-Whitney", "quantitativa, o teste a usar é o t-Student se:")`

`r testarpress <- class_vd[1]=="numeric"`

#now I want to run a chunk with latex and text alike if `testarpress==TRUE`

```{echo=testarpress, eval=testarpress}

- $`r vd`_i \sim N(\mu_i, \sigma_i);i=`r grupo[1]`,`r grupo[2]`$ --- $`r ifelse(sum(SW$norm) > 1, "Verifica-se.", "Rejeita-se.")`$

- $\sigma^2_{`r grupo[1]`}=\sigma^2_{`r grupo[2]`}$ ---  $`r ifelse(Lev$homosc[1], "Verifica-se.", "Rejeita-se.")`$

What I want is to just write the text inside the press chunk if testarpress==TRUE and skip the press chunk if not. This is the output I get:

enter image description here

I get the correct substitutions, but everything is rendered as code, with no latex in the $\mu$ blocks.

cat is not a solution, because the chunk is a full page of text and formulae and r values...

Any idea if this can be accomplished and how? Thanks!

JPMD
  • 644
  • 1
  • 7
  • 19

1 Answers1

0

Actually, after Is there a way to have conditional markdown chunk execution in Rmarkdown? the solution was quite simple, and clean:


Uma vez que a `r vd` é medida numa escala `r ifelse(class_vd[1]=="ordered", "ordinal, o teste a usar é o Wilcoxon-Mann-Whitney", "quantitativa, o teste a usar é o t-Student se:")`

`r testarpress <- class_vd[1]=="numeric"`


`r if(testarpress) {"\\begin{comment}"}`

Put your md code here...

`r if(testarpress) {"\\end{comment}"}`

I did not know the {"\begin{comment}"} feature... ;--)

JPMD
  • 644
  • 1
  • 7
  • 19