我写了一个名为
pipes的包,可以做一些有用的事情:
- 使用
%P>%
将输出打印出来。
- 使用
%ae>%
在输入和输出上使用all.equal
。
- 使用
%V>%
在输出上使用View
,它会为每个相关步骤打开一个查看器。
如果您想查看一些聚合信息,可以尝试%summary>%
,%glimpse>%
或%skim>%
,它们将使用summary
,tibble::glimpse
或skimr::skim
,或者您可以定义自己的管道以显示特定的更改,使用new_pipe
library(dplyr)
library(pipes)
res <- mtcars %P>%
group_by(cyl) %P>%
sample_frac(0.1) %P>%
summarise(res = mean(mpg))
res <- mtcars %ae>%
group_by(cyl) %ae>%
sample_frac(0.1) %ae>%
summarise(res = mean(mpg))
#> group_by(., cyl)
#> [1] "Attributes: < Names: 1 string mismatch >"
#> [2] "Attributes: < Length mismatch: comparison on first 2 components >"
#> [3] "Attributes: < Component \"class\": Lengths (1, 4) differ (string compare on first 1) >"
#> [4] "Attributes: < Component \"class\": 1 string mismatch >"
#> [5] "Attributes: < Component 2: Modes: character, list >"
#> [6] "Attributes: < Component 2: Lengths: 32, 2 >"
#> [7] "Attributes: < Component 2: names for current but not for target >"
#> [8] "Attributes: < Component 2: Attributes: < target is NULL, current is list > >"
#> [9] "Attributes: < Component 2: target is character, current is tbl_df >"
#> sample_frac(., 0.1)
#> [1] "Different number of rows"
#> summarise(., res = mean(mpg))
#> [1] "Cols in y but not x: `res`. "
#> [2] "Cols in x but not y: `qsec`, `wt`, `drat`, `hp`, `disp`, `mpg`, `carb`, `gear`, `am`, `vs`. "
res <- mtcars %V>%
group_by(cyl) %V>%
sample_frac(0.1) %V>%
summarise(res = mean(mpg))
# you'll have to test this one by yourself
debug()
函数,它接近你想要的。你可以与print()
语句一起使用它。这篇关于交叉验证的帖子更多地讨论了它。 - Richard Erickson%>% print() %>%
- 参见此回答:https://dev59.com/BVYO5IYBdhLWcg3wPvRv#54075410 - Emy