Tweak each of the following R commands so that they run correctly:

 1 2 3 4 5 6 7  library(tidyverse) ggplot(dota = mpg) + geom_point(mapping = aes(x = displ, y = hwy)) fliter(mpg, cyl = 8) filter(diamond, carat > 3

ggplot 里面 data 写成了 dota，嗯好的，原来 Hadley 大大也是宅男。

filter 写成了 fliter，然后 = 应该是 ==，口亨，so easy。

 1 2 3 4 5 6 7 8 9  R >>> filter(mpg, cyl == 8) Error in stats::filter(mpg, cyl == 8) : object 'cyl' not found In addition: Warning messages: 1: In data.matrix(data) : NAs introduced by coercion 2: In data.matrix(data) : NAs introduced by coercion 3: In data.matrix(data) : NAs introduced by coercion 4: In data.matrix(data) : NAs introduced by coercion 5: In data.matrix(data) : NAs introduced by coercion 6: In data.matrix(data) : NAs introduced by coercion

 1 2 3 4 5 6 7 8 9  R >>> filter(mpg, cyl == 8) Error in stats::filter(mpg, cyl == 8) : object 'cyl' not found In addition: Warning messages: 1: In data.matrix(data) : NAs introduced by coercion 2: In data.matrix(data) : NAs introduced by coercion 3: In data.matrix(data) : NAs introduced by coercion 4: In data.matrix(data) : NAs introduced by coercion 5: In data.matrix(data) : NAs introduced by coercion 6: In data.matrix(data) : NAs introduced by coercion

 1 2 3 4 5 6 7 8 9  R >>> filter(mpg, cyl == 8) Error in stats::filter(mpg, cyl == 8) : object 'cyl' not found In addition: Warning messages: 1: In data.matrix(data) : NAs introduced by coercion 2: In data.matrix(data) : NAs introduced by coercion 3: In data.matrix(data) : NAs introduced by coercion 4: In data.matrix(data) : NAs introduced by coercion 5: In data.matrix(data) : NAs introduced by coercion 6: In data.matrix(data) : NAs introduced by coercion

。。。卒 。。。

Are you loading dplyr in your .Rprofile?

That’s a bad idea for exactly this reason. It gets loaded before stats, so stats::filter() overrides dplyr::filter()
A better way to handle this is to set the defaultPackages option, and ensure the packages are set in the order you wish to load them. E.g. in your .Rprofile you could have:
 1 2 3 4  .First <- function() { autoloads <- c("dplyr", "ggplot2", "Hmisc") options(defaultPackages = c(getOption("defaultPackages"), autoloads)) }
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  R >>> stats::filter(mpg, cyl == 8) Error in stats::filter(mpg, cyl == 8) : object 'cyl' not found In addition: Warning messages: 1: In data.matrix(data) : NAs introduced by coercion 2: In data.matrix(data) : NAs introduced by coercion 3: In data.matrix(data) : NAs introduced by coercion 4: In data.matrix(data) : NAs introduced by coercion 5: In data.matrix(data) : NAs introduced by coercion 6: In data.matrix(data) : NAs introduced by coercion R >>> dplyr::filter(mpg, cyl == 8) # A tibble: 70 x 11 manufacturer model displ year cyl trans drv cty hwy fl class 1 audi a6 quattro 4.2 2008 8 auto(s6) 4 16 23 p midsize 2 chevrolet c1500 suburban 2wd 5.3 2008 8 auto(l4) r 14 20 r suv 3 chevrolet c1500 suburban