这可能与magrittr (ref1,ref2)的哲学相违背
尽管如此,magrittr仍然会在最简单的嵌套函数中抛出错误。
x <- c(3, 1,2, 3) %>%
sort(unique())
## Error in is.factor(x) : argument "x" is missing, with no defaultx <- c(3, 1,2, 3) %>%
sort(unique(.))
## Error in sort(., unique(.)) :
## 'decreasing' must be a length-1 logical vector.
## Did you intend to set 'partial'?有没有人能解释这种行为,或者如何避免它?
发布于 2021-01-22 22:06:41
我想我可以提供部分答案(关于如何避免这种行为)。
只需将嵌套的函数调用放在大括号中,如下所示:
c(3, 1, 2, 3) %>% {sort(unique(.), decreasing = FALSE)}
# [1] 1 2 3至于为什么会这样,请参阅?magrittr::%>%\。
https://stackoverflow.com/questions/65845846
复制相似问题