1

‘Knit’ing a document from my markdown file, to word or PDF, the text portions are nicely formatted. In this r-chunk I have a text string (in my if/else statement):

```{r  echo=FALSE}
z <- df[is.na(df$column1) | is.na(df$column2) | is.na(df$column3), ]
z <- select(z, column1, column2, column3)

if(nrow(z) == 0){
  print(”Alternative line of text”)
} else{
  kable(z)
}

This gives the typical R-format of the text string "Alternative..." in the generated document:

## [1] "Alternative line of text"

Is there a function other than ”print” to display the text string from the chunk as formatted text, without the “## [1]” (just show it as the rest of the paragraph text)?

(I tried google and searching this site but the lack of vocabulary of exacly what I´m looking for, the tries were unsucessful.)

Edit: The suggested duplicate post did not give me the answer, but the comment given below did!

LErnholm
  • 65
  • 1
  • 2
  • 9
  • 1
    in your chunk options, try setting `results = 'asis'` and then use `cat` instead of `print`. – Benjamin Dec 12 '16 at 18:44
  • Possible duplicate of [r markdown - format text in code chunk with new lines](http://stackoverflow.com/questions/29575768/r-markdown-format-text-in-code-chunk-with-new-lines) – Benjamin Dec 12 '16 at 18:45
  • Thank you - the result = 'asis' and cat() solved my problem! The post you suggest as duplicate did not. – LErnholm Dec 12 '16 at 18:59

0 Answers0