作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作这个小标题没有问题:
library(dplyr)
library(tibble)
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
但是当我尝试用 reprex 包裹它时
reprex::reprex(as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp))
剪贴板显示:
as.tibble(mtcars[2:3, 2:3]) %>% mutate(cyl_x_disp = cyl * disp)
#> Error in eval(expr, envir, enclos): could not find function "%>%"
正确的做法是什么?
最佳答案
您应该将包加载也放入表达式中,否则该示例将无法重现:
reprex::reprex({
library(tibble)
library(dplyr)
as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl * disp)
})
这将产生:
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
关于r - 为什么 reprex 无法渲染 %>% 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43532098/
如何设置 reprex 输出的宽度? 假设我有这样的代码: (x [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
使用 ggplot2 创建非常高的水平条形图时,使用包 reprex 时渲染的图切断一些数据,而轴标签保持在正确的位置。这与相同代码的 ggplot 输出的行为不同。 reprex输出: librar
我制作这个小标题没有问题: library(dplyr) library(tibble) as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl
我制作这个小标题没有问题: library(dplyr) library(tibble) as.tibble(mtcars[2:3,2:3]) %>% mutate(cyl_x_disp = cyl
我是一名优秀的程序员,十分优秀!