首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么reprex不能呈现%>%结果

为什么reprex不能呈现%>%结果
EN

Stack Overflow用户
提问于 2017-04-21 00:43:47
回答 1查看 197关注 0票数 2

我没问题把它做出来:

代码语言:javascript
复制
library(dplyr)
library(tibble)
as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp)

它们产生的结果是:

代码语言:javascript
复制
# A tibble: 2 × 3
    cyl  disp cyl_x_disp
  <dbl> <dbl>      <dbl>
1     6   160        960
2     4   108        432

但是当我试图用reprex包起来时

代码语言:javascript
复制
reprex::reprex(as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp))

剪贴板显示如下:

代码语言:javascript
复制
as.tibble(mtcars[2:3, 2:3]) %>% mutate(cyl_x_disp = cyl * disp)
#> Error in eval(expr, envir, enclos): could not find function "%>%"

正确的方法是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-21 01:25:41

您也应该将包加载放到表达式中,否则示例是不可复制的:

代码语言:javascript
复制
reprex::reprex({
    library(tibble)
    library(dplyr)
    as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp)
})

这将产生:

代码语言:javascript
复制
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
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43532098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档