首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >功率点腐败使用官

功率点腐败使用官
EN

Stack Overflow用户
提问于 2018-12-26 15:48:20
回答 1查看 92关注 0票数 1

我正在使用军官来制作一个ppt,我使用下面的代码在幻灯片中插入一个表。一切都很好。尽管在表中,我需要进行条件文本着色,如果我多次这样做的话,它可以正常工作。但是当我在函数中使用for循环时,代码可以正常工作,但是我的ppt会损坏,并且我看不到ppt中的输出。任何想法

代码语言:javascript
复制
library(data.table)
library(RMySQL)
library(officer) #from source
library(magrittr)
library(flextable)
library(RColorBrewer)
library(ggplot2)

tmrank.ft <- regulartable(data = tm.rank.out) %>% 
    theme_booktabs() %>% 
    autofit() %>%
    merge_v(j=missing_species) %>%
    align(align = 'center') %>%
    align(align = 'center', part = 'header') %>% 
    bold(part = 'header') %>%
    height(height = 1, part = 'header') %>% 
    fontsize(size = 14, part = 'all') %>% 
    width(j=1, width = 1.0 ) %>%
    width(j=2:ncol(tm.rank.out), width = 2.5) %>%
    (
      function(x) {
        ## These for loop causes the issue. If I dont use for loop, it works great.
        for (ii in 2:length(species)) {
          group_result <- group_vector( tm.rank.out.temp, grp.type, 'human')
          if(length(group_result) >0) {
            for (jj in 1:length(group_result)) {
              text_color <- grp.clr[names(group_result)[jj]]
              color(x, i = group_result[[jj]], j = ~ human, color = text_color) 
              }
           }
         }
       }
     )

数据就像

代码语言:javascript
复制
dput(head(tm.rank.out))

结构(排名= 1:6,人= c("AoEC (2.1)","LSEC (2.1)","LMVEC (2)",“前列腺(2)",”跨淋巴细胞(2)",“甲状腺(2)”),cyno = c("AoEC (2.2)",“神经节博士(2.2)",”肾脏(2.2)","LMVEC (2.2)","Retina (2.2)",“Retina(2.2)”,“胆囊(2.1)”,狗=c(“神经节博士(2.6)",”纹状体(2.6)",“骨髓(2.5)","NAc (2.5)",”肾上腺(2.5)",“盲肠(2.5)”),排序=“等级”,类= c("data.table","data.frame“),row.names = c(NA,-6L),.internal.selfref =

代码语言:javascript
复制
dput(head(tm.rank.out.temp))

结构(list= c("1“、"2”、"3“、"4”、"5“、"6")、人= c("AoEC”、"LSEC“、"LMVEC”、“前列腺”、“跨淋巴细胞”、“甲状腺”)、cyno = c("AoEC“、”AoEC“、"DR神经节”、“肾脏”、"LMVEC“、"Retina”、“胆囊”)、狗= c("DR神经节“、”纹状体“、“骨髓”、"NAc“、”肾上腺“、”盲肠“)、类= c("data.table”、"data.frame“)、row.names = c(NA,-6L)、.internal.selfref =)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-27 15:26:17

我想,我必须把"x“放在函数的末端循环中。所以就像

代码语言:javascript
复制
tmrank.ft <- regulartable(data = tm.rank.out) %>% 
theme_booktabs() %>% 
autofit() %>%
merge_v(j=missing_species) %>%
align(align = 'center') %>%
align(align = 'center', part = 'header') %>% 
bold(part = 'header') %>%
height(height = 1, part = 'header') %>% 
fontsize(size = 14, part = 'all') %>% 
width(j=1, width = 1.0 ) %>%
width(j=2:ncol(tm.rank.out), width = 2.5) %>%
(
  function(x) {
    ## These for loop causes the issue. If I dont use for loop, it works great.
    for (ii in 2:length(species)) {
      group_result <- group_vector( tm.rank.out.temp, grp.type, 'human')
      if(length(group_result) >0) {
        for (jj in 1:length(group_result)) {
          text_color <- grp.clr[names(group_result)[jj]]
          color(x, i = group_result[[jj]], j = ~ human, color = text_color) 
          }
       }
     }
    x
   }
 )
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53934159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档