小编eco*_*ian的帖子

如何判断管道操作员是否是链中的最后一个(或第一个)?

我最近一直在玩创建自己的管道,使用了很棒的pipe_with()功能magittr.我期待跟踪当前链中的管道数量(因此我的管道可以根据其在链中的位置而表现不同).我以为我从magrittrgithub页面得到了这个例子的答案:

# Create your own pipe with side-effects. In this example 
# we create a pipe with a "logging" function that traces
# the left-hand sides of a chain. First, the logger:
lhs_trace <- local({
  count <- 0
  function(x) {
    count <<- count + 1
    cl <- match.call()
    cat(sprintf("%d: lhs = %s\n", count, deparse(cl[[2]])))
  }
})

# Then attach it to a new pipe
`%L>%` <- pipe_with(lhs_trace)

# Try it out.
1:10 %L>% sin …
Run Code Online (Sandbox Code Playgroud)

r piping magrittr

5
推荐指数
1
解决办法
188
查看次数

使用反应值时,ggvis交互式图形无法正常工作

我遇到以下示例ggvis代码的问题,该代码用于创建一个图表,当您将鼠标悬停在该组的任何成员上时,该图表会突出显示整组点.然后,当你徘徊时,我希望突出显示消失.发生的事情是突出显示最初起作用,但是当你悬停时,突出显示保持不变,只有当你将鼠标悬停在另一组点上然后再次将它们悬停时它们才会消失.

library(magrittr)
library(dplyr)
library(ggvis)
library(shiny)

dat <- iris %>% select(-Species) %>% dist %>% cmdscale %>% data.frame %>% tbl_df %>% mutate(Species = iris$Species) %>% 
data.frame
Props <- reactiveValues(Size = rep(50, length.out = nrow(dat)), Stroke = rep("white", length.out = nrow(dat)))
hoveron <- function(data, ...) {
    Props$Size[dat$Species == data$Species] <- 150 
    print("hoveron!")
    Props$Stroke[dat$Species == data$Species] <- "black"
}
hoveroff <- function(...) {
    Props$Size <- rep(50, length.out = nrow(dat))
    print("hoveroff!")
    Props$Stroke <- rep("white", length.out = nrow(dat))
}

dat %>%
ggvis(~X1, ~X2, fill …
Run Code Online (Sandbox Code Playgroud)

r shiny ggvis

5
推荐指数
0
解决办法
696
查看次数

标签 统计

r ×2

ggvis ×1

magrittr ×1

piping ×1

shiny ×1