是否有一个命令可以添加到不会破坏流量的tidyverse管道,但会产生一些副作用,比如打印出来的东西。我想到的用例是这样的。如果是管道
<Pane HBox.hgrow="ALWAYS"></Pane>
我想在管道中添加一些不会修改最终结果的命令,但会打印出一些进度或状态。也许是这样的:
data %>%
mutate(new_var = <some time consuming operation>) %>%
mutate(new_var2 = <some other time consuming operation>) %>%
...
是否已存在此类data %>%
mutate(new_var = <some time consuming operation>) %>%
command_x(print("first operation done")) %>%
mutate(new_var2 = <some other time consuming operation>) %>%
...
?
答案 0 :(得分:3)
您可以轻松编写自己的功能
pass_through <- function(data, fun) {fun(data); data}
并像
一样使用它mtcars %>% pass_through(. %>% ncol %>% print) %>% nrow
这里我们使用. %>%
语法创建一个匿名函数。您也可以使用
mtcars %>% pass_through(function(x) print(ncol(x))) %>% nrow
答案 1 :(得分:0)
在更简单的print
案例中充实MrFlick的答案:
# Your pipe-print function
pipe_print = function(data) {print(data); data}
# Let's try it in action:
mtcars %>%
mutate(kmpl = 0.425*mpg) %>% # Convert to km-per-liter
pipe_print() %>% # Pipe print! Did it work?
group_by(cyl) %>% # Continue processing...
summarise(mpg = mean(mpg))
答案 2 :(得分:0)
您可以使用匿名函数即时执行操作
[
{key: 'animation-iteration-count', value: 1},
{key: 'animation-name', value:none },
{key: 'animation-play-state', value: running },
]