How to print tables in slidify?

I want to show the contents of data.frame as a table in slidify. I know how to create Markdown tables from data.frames using the ascii library, but when I try to use it with slidify, instead of seeing the table in the output html, I see a bunch of information about the internal structure of the ascii table.

So how do you type, for example. head (some.data.frame) in slidify?

Edit:

Actually I want to show the table of representations in the CRAN task view. Right now I typed the table manually in Markdown:

Views | Content --------|-------- Bayesian| Bayesian Inference ChemPhys| Chemometrics and Computational Physics ClinicalTrials| Clinical Trial Design, Monitoring, and Analysis 

I want to create this table automatically from the ctv package. I collected all the necessary information in the data.frame file:

 library(ctv) list.of.views <- available.views() X <- data.frame(View=NA,Description=NA) for(i in 1:length(list.of.views)) { X[i,1] <- list.of.views[[i]]$name X[i,2] <- list.of.views[[i]]$topic } head(X) 

that leads to

  View Description 1 Bayesian Bayesian Inference 2 ChemPhys Chemometrics and Computational Physics 3 ClinicalTrials Clinical Trial Design, Monitoring, and Analysis 4 Cluster Cluster Analysis & Finite Mixture Models 5 DifferentialEquations Differential Equations 6 Distributions Probability Distributions 

I'm doing markdown with ascii package

 library(ascii) print(ascii(X[1:6,1:2]), type = 'pandoc') 

which shows this in terminal R:

  **View** **Description** --- ----------------------- ------------------------------------------------- 1 Bayesian Bayesian Inference 2 ChemPhys Chemometrics and Computational Physics 3 ClinicalTrials Clinical Trial Design, Monitoring, and Analysis 4 Cluster Cluster Analysis & Finite Mixture Models 5 DifferentialEquations Differential Equations 6 Distributions Probability Distributions --- ----------------------- ------------------------------------------------- Warning messages: 1: In rep(rownames, length = nrow(x)) : 'x' is NULL so the result will be NULL 2: In rep(colnames, length = ncol(x)) : 'x' is NULL so the result will be NULL 

but when this last line is print in the code block in my Rmd and slidify , I see the following contents on my slide:

 ## <S4 Type Object> ## attr(,".xData") ## <environment: 0x03b904d8> ## attr(,"class") ## [1] "asciiTable" ## attr(,"class")attr(,"package") ## [1] "ascii" 
+4
source share
2 answers

Thanks to Tyler Rinker I was able to create a table in which I wanted to use xtable

 --- ```{r, results='asis'} print(xtable(X[1:6,1:2]), type = "html") ``` 
+6
source

If you want a markdown, I can highly recommend the pander package, which can convert R objects to different markup format dialects. Quick example:

  • Download package

     library(pander) 
  • Create a layout table in your default multi-line Pandoc demo data:

     > pander(X[1:6,1:2]) ----------------------------------------------- View Description --------------------- ------------------------- Bayesian Bayesian Inference ChemPhys Chemometrics and Computational Physics ClinicalTrials Clinical Trial Design, Monitoring, and Analysis Cluster Cluster Analysis & Finite Mixture Models DifferentialEquations Differential Equations Distributions Probability Distributions ----------------------------------------------- 
  • Or in grid format:

     > pander(X[1:6,1:2], style = 'grid') +-----------------------+---------------------------+ | View | Description | +=======================+===========================+ | Bayesian | Bayesian Inference | +-----------------------+---------------------------+ | ChemPhys | Chemometrics and | | | Computational Physics | +-----------------------+---------------------------+ | ClinicalTrials | Clinical Trial Design, | | | Monitoring, and Analysis | +-----------------------+---------------------------+ | Cluster | Cluster Analysis & Finite | | | Mixture Models | +-----------------------+---------------------------+ | DifferentialEquations | Differential Equations | +-----------------------+---------------------------+ | Distributions | Probability Distributions | +-----------------------+---------------------------+ 
  • Simple sieve without automatic line break:

     > pander(X[1:6,1:2], style = 'simple', split.cells = Inf) View Description --------------------- ----------------------------------------------- Bayesian Bayesian Inference ChemPhys Chemometrics and Computational Physics ClinicalTrials Clinical Trial Design, Monitoring, and Analysis Cluster Cluster Analysis & Finite Mixture Models DifferentialEquations Differential Equations Distributions Probability Distributions 
  • And PHP Extra Markdown / rmarkdown :

     > pander(X[1:6,1:2], style = 'rmarkdown', split.cells = Inf) | View | Description | |:---------------------:|:-----------------------------------------------:| | Bayesian | Bayesian Inference | | ChemPhys | Chemometrics and Computational Physics | | ClinicalTrials | Clinical Trial Design, Monitoring, and Analysis | | Cluster | Cluster Analysis & Finite Mixture Models | | DifferentialEquations | Differential Equations | | Distributions | Probability Distributions | 

There are many global or custom options for setting tables (e.g., alignment, separation of settings, selection of cells, etc.)

+3
source

Source: https://habr.com/ru/post/1502243/


All Articles