将参数传递给函数

时间:2016-10-19 07:29:29

标签: r arguments

我正在尝试将参数传递给formatter函数,但感觉我错过了一些非常简单的东西。

d <-  function(input) (formatter("span", 
                     style = ~ style(color = ifelse(sessions_diff < 0, "red", "green")),
                             ~ icontext(ifelse(sessions_diff < 0, "arrow-down", "arrow-up"), input))
                      )

我期待d('mycol')的输出为

formatter(.tag = "span", 
        style = ~style(color = ifelse(sessions_diff < 0, "red", "green")),               
                  ~icontext(ifelse(sessions_diff < 0, "arrow-down", "arrow-up"), 'mycol'))

相反,我正在

formatter(.tag = "span", 
                  style = ~style(color = ifelse(sessions_diff < 0, "red", "green")),               
                  ~icontext(ifelse(sessions_diff < 0, "arrow-down", "arrow-up"), input))

输入被视为文字文本而不是参数。

为了提供更多上下文,最终目标是使用lapply,以便函数将根据delta.colnames列表进行更新。

delta.colnames <- c('sessions_diff','newUsers_diff','bounceRate_diff','transactions_diff')

lapply(delta.colnames, FUN=function(delta) formatter("span", 
                                   style = ~ style(color = ifelse(delta < 0, "red", "green")),
                                   ~ icontext(ifelse(delta < 0, "arrow-down", "arrow-up"), delta)))

经过大量的研究,我迷失了,并希望有人能够指出我为什么会这样?

0 个答案:

没有答案