nev*_*int 2 r dplyr magrittr tidyverse reprex
我制作这个小标题没有问题:
library(dplyr)
library(tibble)
as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp)
Run Code Online (Sandbox Code Playgroud)
产生这个:
# A tibble: 2 × 3
cyl disp cyl_x_disp
<dbl> <dbl> <dbl>
1 6 160 960
2 4 108 432
Run Code Online (Sandbox Code Playgroud)
但是当我试图用reprex包裹它时
reprex::reprex(as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp))
Run Code Online (Sandbox Code Playgroud)
剪贴板显示了这一点:
as.tibble(mtcars[2:3, 2:3]) %>% mutate(cyl_x_disp = cyl * disp)
#> Error in eval(expr, envir, enclos): could not find function "%>%"
Run Code Online (Sandbox Code Playgroud)
正确的做法是什么?
您还应该将包加载放入表达式中,否则该示例不可重现:
reprex::reprex({
library(tibble)
library(dplyr)
as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp)
})
Run Code Online (Sandbox Code Playgroud)
这将产生:
library(tibble)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
as.tibble(mtcars[2:3, 2:3]) %>% mutate(cyl_x_disp = cyl * disp)
#> # A tibble: 2 × 3
#> cyl disp cyl_x_disp
#> <dbl> <dbl> <dbl>
#> 1 6 160 960
#> 2 4 108 432
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
152 次 |
| 最近记录: |