% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gridtable.R
\name{as_gridtable}
\alias{as_gridtable}
\title{Coerce to Gridtable}
\usage{
as_gridtable(x, ...)
}
\arguments{
\item{x}{object}

\item{...}{passed arguments}
}
\value{
see methods
}
\description{
Coerces to "gridtable", i.e. the Pandoc construct "grid table" Generic,
with method \code{\link{as_gridtable.character}}.
}
\examples{
# as_gridtable() lets you create and render small data tables on-the-fly.

library(magrittr)
library(tablet)
library(yamlet)
library(kableExtra)
'+--+--+--+
|study | subjects | doses |
+==+==+==+
| 001 | 20 | 5 mg, 10 mg |
+--+--+--+
| 002 | 40 | 5 mg, 10 mg |
|     |    | 15 mg, 20 mg, 30 mg |
+--+--+--+' \%>\% 
as_gridtable

# We see that as_gridtable cleans up our Pandoc grid table markdown.
# We copy it here and render it with kableExtra::kbl().

'
+-------+----------+---------------------+
| study | subjects | doses               |
+=======+==========+=====================+
| 001   | 20       | 5 mg, 10 mg         |
+-------+----------+---------------------+
| 002   | 40       | 5 mg, 10 mg         |
|       |          | 15 mg, 20 mg, 30 mg |
+-------+----------+---------------------+
' \%>\%
as_gridtable \%>\%
as.data.frame(scale = 0.9) \%>\% # or: options(tablet.gridtable.scale = 0.9)
decorations

# We see that a gridtable when converted to data.frame
# has scalable column width attributes.
# Widths are controlled by longest line of text, including column name.
# kbl will try to honor widths.
# kbl() will call as.data.frame() implicitly if you pass a gridtable:

'
+-------+----------+---------------------+
| study | subjects | doses               |
+=======+==========+=====================+
| 001   | 20       | 5 mg, 10 mg         |
+-------+----------+---------------------+
| 002   | 40       | 5 mg, 10 mg         |
|       |          | 15 mg, 20 mg, 30 mg |
+-------+----------+---------------------+
' \%>\%
as_gridtable \%>\%
kbl(
  label = "studies",
  booktabs = TRUE,
  caption = "Study Characteristics" 
) \%>\%
  kable_styling(font_size = 9) \%>\%
  footnote(
    threeparttable = TRUE,
    general_title = "",
    general = "For more details, see study protocols."
  )
  
# We can start with a data.frame:

data.frame(
  study = c('001','002'), 
  subjects = c(20, 40)
) \%>\%
as_gridtable

# We can integrate decorations:

'
+-------+----------+
| study | subjects |
+=======+==========+
| 001   | 20       |
+-------+----------+
| 002   | 40       |
+-------+----------+
' \%>\%
as_gridtable \%>\%
as.data.frame \%>\%
decorate('
  study: [ Study, [ ST001: "001", ST002: "002" ]]
  subjects: [ N Subjects ]
') \%>\%
resolve \%>\%
kbl(
  label = "studies",
  booktabs = TRUE,
  caption = "Study Characteristics"
) \%>\%
kable_styling()
}
\seealso{
Other gridtable: 
\code{\link{as.data.frame.gridtable}()},
\code{\link{as_calibrated}()},
\code{\link{as_calibrated.data.frame}()},
\code{\link{as_gridtable.character}()},
\code{\link{as_gridtable.data.frame}()},
\code{\link{kbl}()},
\code{\link{kbl.calibrated}()},
\code{\link{kbl.default}()},
\code{\link{kbl.gridtable}()},
\code{\link{print.gridtable}()}
}
\concept{gridtable}
\keyword{internal}
