Hard time with df_print: paged when using a function


#1

I am trying to print out a crosstab from a function but I would like to use the paged printing of data frames.
In the function, I can use print(), but that isn’t paged. I tried using knitr::knit_print(), but that suppresses all of the output. I’m hoping there is a simple explanation / knowledge gap.

Is there a better way to send .Rmd? Here, I’ve inserted a space at the end of each code chunk (`` `)

---
title: "Untitled"
output: 
  html_document:
    df_print: paged
---

```{r}
k <- function(x) {
  knitr::knit_print(x)
}
`` ` 

```{r}
p <- function(x) {
  print(x)
}
`` `

```{r}
suppressPackageStartupMessages(library(tidyverse))
`` `

# knit_print

Paged printing!

```{r}
k(mtcars)
`` `

# print

Not paged printing.

```{r}
p(mtcars)
`` `

# knit_print pwalk

Suppressed output

```{r,  results='asis', cols.print=3, rows.print=3}
mtcars %>% 
  nest(-am) %>% 
  pwalk(.l=as.list(.), .f= ~k(..2))
`` `

# print pwalk

Printed output; but not paged

```{r, cols.print=3, rows.print=3}
mtcars %>% 
  nest(-am) %>% 
  pwalk(.l=as.list(.), .f= ~p(..2))
`` `
> devtools::session_info("rmarkdown")
Session info ----------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.2 (2016-10-31)
 system   x86_64, linux-gnu           
 ui       RStudio (1.1.353)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/New_York            
 date     2018-01-25                  

Packages --------------------------------------------------------------------------------------------------------------------------------------------------
 package   * version date       source         
 backports   1.1.2   2017-12-13 cran (@1.1.2)  
 base64enc   0.1-3   2015-07-28 CRAN (R 3.3.2) 
 digest      0.6.13  2017-12-14 cran (@0.6.13) 
 evaluate    0.10.1  2017-06-24 cran (@0.10.1) 
 highr       0.6     2016-05-09 CRAN (R 3.3.2) 
 htmltools   0.3.6   2017-04-28 cran (@0.3.6)  
 jsonlite    1.5     2017-06-01 cran (@1.5)    
 knitr       1.18    2017-12-27 cran (@1.18)   
 magrittr    1.5     2014-11-22 CRAN (R 3.3.2) 
 markdown    0.8     2017-04-20 cran (@0.8)    
 mime        0.5     2016-07-07 CRAN (R 3.3.2) 
 Rcpp        0.12.13 2017-09-28 cran (@0.12.13)
 rmarkdown   1.8     2017-11-17 cran (@1.8)    
 rprojroot   1.3-2   2018-01-03 cran (@1.3-2)  
 stringi     1.1.6   2017-11-17 cran (@1.1.6)  
 stringr   * 1.2.0   2017-02-18 CRAN (R 3.3.2) 
 yaml        2.1.16  2017-12-12 cran (@2.1.16) 

#2

Here is the easiest solution that worked for me. It breaks k(mtcars), but unlocks the pwalk(.l=as.list(.), .f= ~k(..2)).

```{r}
k <- function(x) {
  knitr::knit_print(x) %>% cat()
}
`` `