我在Windows 7 x64操作系统上使用R 3.5.1。
我的软件包版本为:
柔性表:0.5.1
人员:0.3.2
tidyverse:1.2.1
提迪尔:0.8.2
我正在尝试创建多个弹性表,然后在单个块中将其打印到Word。我也不想在Word Doc中使用实际的R代码,因此我将echo设置为FALSE。但是,我遇到了一些奇怪的事情。
如果我使用以下代码(echo = T):
```{r, echo = F, warning=FALSE, message=FALSE}
library(tidyverse)
library(flextable)
library(officer)
```
```{r, echo = T}
iris_data <- head(iris, n = 10)
iris_data_ft <- iris_data %>% flextable() %>%
hline(part = 'header', border = fp_border(color = "black", width = 3)) %>%
align(align ='center', part = 'all') %>%
align(j = 1, align ='left', part = 'all') %>%
add_header_lines('this is a test')
iris_data_ft
iris_data2 <- tail(iris, n = 10)
iris_data2_ft <- iris_data2 %>% flextable() %>%
hline(part = 'header', border = fp_border(color = "black", width = 3)) %>%
align(align ='center', part = 'all') %>%
align(j = 1, align ='left', part = 'all') %>%
add_header_lines('this is a test')
iris_data2_ft
```
如果我使用完全相同的代码,但是echo = F:
```{r, echo = F}
iris_data <- head(iris, n = 10)
iris_data_ft <- iris_data %>% flextable() %>%
hline(part = 'header', border = fp_border(color = "black", width = 3)) %>%
align(align ='center', part = 'all') %>%
align(j = 1, align ='left', part = 'all') %>%
add_header_lines('this is a test')
iris_data_ft
iris_data2 <- tail(iris, n = 10)
iris_data2_ft <- iris_data2 %>% flextable() %>%
hline(part = 'header', border = fp_border(color = "black", width = 3)) %>%
align(align ='center', part = 'all') %>%
align(j = 1, align ='left', part = 'all') %>%
add_header_lines('this is a test')
iris_data2_ft
```
最后,如果我将两个弹性表的一个块拆分为两个单独的块并设置echo = F:
```{r, echo = F}
iris_data <- head(iris, n = 10)
iris_data_ft <- iris_data %>% flextable() %>%
hline(part = 'header', border = fp_border(color = "black", width = 3)) %>%
align(align ='center', part = 'all') %>%
align(j = 1, align ='left', part = 'all') %>%
add_header_lines('this is a test')
iris_data_ft
```
```{r, echo = F}
iris_data2 <- tail(iris, n = 10)
iris_data2_ft <- iris_data2 %>% flextable() %>%
hline(part = 'header', border = fp_border(color = "black", width = 3)) %>%
align(align ='center', part = 'all') %>%
align(j = 1, align ='left', part = 'all') %>%
add_header_lines('this is a test')
iris_data2_ft
```
虽然我不介意将弹性表分成不同的块,但我想知道为什么会这样。任何指导将不胜感激。谢谢!
答案 0 :(得分:1)
这是一种解决方法:
/*The matrix are initialized as follows*/
for (i = 0; i < n; i++)
for (j = 0; j < n; j++){
*(A+i*n+j) = 1 / ((REAL_T) (i+j+1));
*(B+i*n+j) = 1.0;
*(C+i*n+j) = 1.0;
}
/*End of initialization*/
答案 1 :(得分:0)
我想这个问题已经用新版本的 flextable 解决了。如果我将以下两个块的代码放入一个 .Rmd 文档中并按字词进行编译,则它可以毫无问题地编译并显示表格,即使将其放入一个带有 echo = F
的块中也是如此。只想添加:在某些情况下,将 results='asis'
- 'as is'-选项(原始 Markdown 解析) - 添加到您的块头以防止解析表时出现错误可能会有所帮助,请检查:{{3} }.
```{r, echo = F, warning=FALSE, message=FALSE}
library(tidyverse)
library(flextable)
library(officer)
```
```{r, echo = F}
iris_data <- head(iris, n = 10)
iris_data_ft <- iris_data %>% flextable() %>%
hline(part = 'header', border = fp_border(color = "black", width = 3)) %>%
align(align ='center', part = 'all') %>%
align(j = 1, align ='left', part = 'all') %>%
add_header_lines('this is a test')
iris_data_ft
iris_data2 <- tail(iris, n = 10)
iris_data2_ft <- iris_data2 %>% flextable() %>%
hline(part = 'header', border = fp_border(color = "black", width = 3)) %>%
align(align ='center', part = 'all') %>%
align(j = 1, align ='left', part = 'all') %>%
add_header_lines('this is a test')
iris_data2_ft
```