0

im aware of sink() and capture.output(). Somehow I cant get my desired result.

example of my codeblock

mtcars[1:2,1:2]
#this is awesome,
mtcars[1:2,1:2] %>% rowMeans(.)

Desired output in my txt file: Must look 100% like in my console:

> mtcars[1:2,1:2]
              mpg cyl
Mazda RX4      21   6
Mazda RX4 Wag  21   6
>     #this is awesome,
>     mtcars[1:2,1:2] %>% rowMeans(.)
    Mazda RX4 Mazda RX4 Wag 
         13.5          13.5

Preudocode

It would be nice to have something like this:

console2txt(file="text.txt")
    mtcars[1:2,1:2]
    #this is awesome,
    mtcars[1:2,1:2] %>% rowMeans(.)
dev.off()

Is there a solution to caputure the entire console of a "script block".

Community
  • 1
  • 1
Andre Elrico
  • 10,956
  • 6
  • 50
  • 69

1 Answers1

1

Usually I do this with RMarkdown.

---
output: rtf_document
---
```{r}
mtcars[1:2,1:2]
#this is awesome,
mtcars[1:2,1:2] %>% rowMeans(.)
```
edavidaja
  • 698
  • 1
  • 6
  • 15