0
votes

I would like to indent the result of the code output produced by an R Markdown chunk (PDF output). I have many chunks in my file but I would like to increase the indent ONLY on a specific chunk output results. For example, I need to alter the indent once I invoke a data.frame print-out.

I tried indent= " " chunk option but it doesn't work well because the graph that I also produce in the same chunk strangely dissapeared from the PDF output.

I tried to add a second chunk just to print the text output with the indent=" " chunk option but it also doesn't work very well because of the following reason:

  1. Original chunk:
```{r, warning=FALSE, fig.height = 5, message=TRUE}
library(qualityTools)
b.data <- data.frame(cause = c("Cause 1","Cause 2","Cause 3","Cause 4","Cause 5","Cause 6","Cause 7"), 
        count = c(1,1,1,1,1,1,1),
        cost = c(0.0327,0.0078,0.0026,0.0162,0.0000,0.0000,0.0158))


b.vector <- b.data$cost
names(b.vector) <- b.data$cause

data.pareto <- paretoChart(b.vector, las = 2, col = "#65BBA9", border = "#000000", main = "Pareto Chart", ylab = "EUR", percentVec = c(0, 0.2, 0.4, 0.6, 0.80, 1), showTable = FALSE)

text output:

EUR 0.0327 0.0162 0.0158 0.0078 0.0026 0 0

Cum. EUR 0.0327 0.0489 0.0647 0.0725 0.0751 0.0751 0.0751

Percentage 43.5% 21.6% 21.0% 10.4% 3.5% 0.0% 0.0%

Cum. Percentage 43.5% 65.1% 86.2% 96.5% 100.0% 100.0% 100.0%

  1. Additional chunk
```{r, warning=FALSE, fig.height = 5, message=TRUE, indent="      "}
data.pareto

text output:

EUR 0.03270 0.01620 0.01580 0.00780 0.002600 0.0000 0.0000

Cum. EUR 0.03270 0.04890 0.06470 0.07250 0.075100 0.0751 0.0751

Percentage 43.54194 21.57124 21.03862 10.38615 3.462051 0.0000 0.0000

Cum. Percentage 43.54194 65.11318 86.15180 96.53795 100.000000 100.0000 100.0000

So the text output in 2) is formatted differently than text output of 1).

I would like to preserve the formatting of 1).

2

2 Answers

0
votes

It sounds like the indent works for you, with the side effect of losing the graph. Can't you just add a separate chunk for creating the graph?

0
votes

I partially solved my problem by using kable table output of the data.pareto data frame. By using the position = "left" OR position = "center" option of kable I was able to alter the indent of the print-out. However this is not the optimal solution because I need more fine adjustment of the indent.