Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Conditionally display block of text with code inside string section

I would like to conditionally display this block of text but I don’t understand how to put the part nrow(subset(df, column == 1)) readable for the program and not inside the string.

`r if(nrow( subset(df,column == 1) != 0){"Multiple choice variable with nrow(subset(df, column == 1)) missing values."}`

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Using paste you could do:

Also note that there was a bug in your condition which I fixed.

---
title: "Untitled"
output: html_document
date: '2022-07-22'
---

```{r}
df <- data.frame(
  column = 1:2
)
```

`r if (nrow( subset(df,column == 1)) != 0) paste("Multiple choice variable with", nrow(subset(df, column == 1)), "missing values.") else ""`

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading