Print bold text conditionally in R markdown

Viewed 124

I have an issue with R markdown when I try to print some bold text subject to a condition.

I want R to evaluate whether a string is empty or not. If the string is not empty it should be printed in bold. The final document is written in word. Here's the code that I have used:

myvar = "some string variable"

**`r if (myvar != "")  {myvar}`**

This code works fine when the string is not empty as it prints the variable correctly. If the string is empty, however, I expect no actions but the code returns a black line instead. I attached a screenshort of the final document, where you can see 7 black lines, one for each empty string evaluated with the previous code:

Image depicting the problem

0 Answers
Related