0

I'm new to using Rmarkdown. I have a loop from which I extract a set of results for each iteration. This is fine. However, I am unable to get the text to print as bold. Here is some example code:

```{r echo=FALSE}
x <- data.frame(var1 = c(1,0.99,0.98,0.97,0.95), 
            var2 = c(1,0.995,0.99,0.98,0.97),
            var3 = c(1,0.98,0.96,0.94,0.90)
            )

year <- 1980:2010


# Do stuff across the loop:
for(j in 1:nrow(x)){
  temp_var1 <- constant1 * var1[j] * var2[j] * var3[j]
  temp_var2 <- constant2 * var1[j] * var2[j] * var3[j]


  q025 <- round(sapply(temp_var1[, ], quantile, probs=0.025))
  q975 <- round(sapply(temp_var2[, ], quantile, probs=0.975))
  proj <- as.data.frame(cbind(year, q025, q975))
  row.names(proj) <- NULL

  # Print stuff:
  **print(x[j,])**
  print(proj)
  cat('\n\n\n\n')   
} # close j loop
```

Thanks for any help.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Mark
  • 37
  • 1
  • 8

1 Answers1

2

I'm not really sure what you want to do with the for-loop code but you can copy this short Rmarkdown snippet to your own new Rmarkdown document to render bold text from within a code chunk:

## Display some bold text from inside a chunk

```{r results='asis'}
cat("I am a normal statement")
cat("**some bold text**")
```

## Bold text with a for loop

```{r results='asis'}
for(i in 1:5){
  cat("Number: **", i, "**\n\n", sep = "")
}
```
markdly
  • 4,394
  • 2
  • 19
  • 27
  • Thanks. However I'm trying to do this within a {r echo=FALSE} loop, so that much of the output is suppressed, other than that indicated by the cat() comand.i.e. when I use cat("Number: **", i, "**\n\n", sep = "") within the r echo loop, only **i** is printed to the Word document, but not in bold. – Mark Nov 23 '17 at 10:02
  • @Mark, it's fine to have more than one option set in the chunk. Does replacing `{r results='asis'}` with `{r echo=FALSE, results='asis'}` help? – markdly Nov 23 '17 at 10:22
  • Thanks. However, the tabulated results are now just a continuous block of numbers. – Mark Nov 28 '17 at 09:10