我想在 slidify 中将 data.frame 的内容显示为表格。
我知道如何使用 ascii 库从 data.frames 创建 Markdown 表,但是当我尝试将它与 slidify 一起使用时,我看到的是一堆关于 ascii 表内部结构的信息,而不是在输出 html 中看到表。

那么你如何打印,例如滑动头(some.data.frame)?

编辑:

事实上,我想在 CRAN 任务 View 中显示一个 View 表,
现在我在 Markdown 中手动输入表格:

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

我想从 ctv 包自动创建这个表。我在 data.frame 中收集了我需要的信息:
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)

这导致
                   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

我使用 ascii 包进行 Markdown
library(ascii)
print(ascii(X[1:6,1:2]), type = 'pandoc')

在 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

但是当我的 print 文件和 Rmd 的代码块中的最后 slidify 行时,我在幻灯片中看到以下内容:
## <S4 Type Object>
## attr(,".xData")
## <environment: 0x03b904d8>
## attr(,"class")
## [1] "asciiTable"
## attr(,"class")attr(,"package")
## [1] "ascii"

最佳答案

感谢 Tyler Rinker 我设法使用 xtable 创建了我想要的表

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

关于r - 如何在 slidify 中打印表格?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18810749/

10-12 17:24