Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format text inside R code chunk

Tags:

I am making some slides inside Rstudio following instructions here: http://rmarkdown.rstudio.com/beamer_presentation_format.html

How do I define text size, colors, and "flow" following numbers into two columns?

```{r,results='asis', echo=FALSE}
rd <- sample(x=1e6:1e7, size = 10, replace = FALSE)
cat(rd, sep = "\n")

```

Output is either HTML (ioslides) or PDF (Beamer)

Update:

Currently the code above will only give something like the following

6683209
1268680
8412827
9688104
6958695
9655315
3255629
8754025
3775265
2810182

I can't do anything to change text size, color or put them into a table. The output of R codechunk is just plain text. Maybe it is possible to put them in a table indeed, as mentioned at this post:

http://tex.aspcode.net/view/635399273629833626273734/dynamically-format-labelscolumns-of-a-latex-table-generated-in-rknitrxtable

But I don't know about text size and color.

Update 2:

The idea weaving native HTML code to R output is very useful. I haven't thought of that. This however only works if I want to output HTML. For PDF output, I have to weave the native Latex code with R output. For example, the code following works using "knitr PDF" output:

```{r,results='asis', echo=FALSE}
cat("\\textcolor{blue}{") 
rd <- sample(x=1e6:1e7, size = 10, replace = FALSE) 
for (n in rd) {
cat(paste0(n, '\\newline \n')) } 
cat("}")
```