'Hide NA values in .Rmd output

I build a shiny App that lets the user download a pdf report using r markdown.

The user can select an ID and variables (such as Dates...) from a data frame corresponding to this ID are printed in the .Rmd document.

The code inside the .Rmd looks like this:

Date of birth: `r Datebirth()`

Let's say that no date of birth has been filled into the data frame. The output on the pdf document looks like this:

  • Date of birth: NA

When no Date of birth is filled into the dataframe I want that neither "Date of birth" nor "NA" are printed.

Can someone help?



Solution 1:[1]

I would try this "one-line" solution:

`r ifelse(is.na(Datebirth()), "", paste("Date of birth":, Datebirth()))`

This works in a "normal" Rmd file with a "normal variable", but I don't know if it works with a dynamic shiny variable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bt-koch