Last active
March 27, 2019 15:51
-
-
Save rkrug/fcb145f5ebf27ded865cca943332dbf6 to your computer and use it in GitHub Desktop.
kable table as return from function as character
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "test" | |
author: "Rainer M Krug" | |
date: "3/27/2019" | |
output: | |
html_document: default | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = TRUE) | |
library(knitr) | |
``` | |
```{r} | |
x <- data.frame(a = 1:10, b = runif(10)) | |
``` | |
This works: | |
```{r, results = "asis"} | |
cat("Some text") | |
knitr::kable(x) | |
``` | |
Now consider the following function: | |
```{r} | |
fun <- function (x) { | |
result <- | |
paste0( | |
"Some text\n\n", | |
knitr::kable(x, format = "markdown") | |
) | |
return(result) | |
} | |
``` | |
How to make this work? | |
This does not work: | |
```{r , results = "asis"} | |
fun(x) | |
``` | |
This also does not work: | |
```{r , results = "asis", comment = NA} | |
cat(fun(x)) | |
``` | |
How can I make this work? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment