包dplyr和choroplethr是不兼容的

时间:2016-08-04 19:13:59

标签: r dplyr choroplethr

运行以下代码

library(dplyr)

mtcars %>% 
 group_by(cyl) %>% 
 summarise (mean_mpg = mean(mpg))

#A tibble:3 x 2

 cyl mean_mpg
<dbl>    <dbl>
1     4 26.66364
2     6 19.74286
3     8 15.10000

加载choroplethr后,即使我们再次加载dplyr也不起作用

library(choroplethr)

mtcars %>% 
 group_by(cyl) %>% 
 summarise (mean_mpg = mean(mpg))

mean_mpg
1 20.09062

看起来这两个包是不兼容的。我以前使用过它们没有问题,但在升级到新版本的R,RStudio和两个软件包后,它们不再合作。

1 个答案:

答案 0 :(得分:2)

加载choroplethr时,它也会加载plyr。正如一再提到的那样,加载plyr后不要加载dplyr

在您的情况下,首先加载choroplethr,然后加载dplyr,一切都应该正常。

library(choroplethr)
Loading required package: acs
Loading required package: stringr
Loading required package: plyr
Loading required package: XML

Attaching package: ‘acs’

The following object is masked from ‘package:base’:

    apply

虽然choroplethr仅取决于acs,但acs取决于plyr;因此,当您检查choroplethr CRAN页面时,可能并不明显它也会加载plyr