[R] Understanding namespace for plyr / dplyr

Hadley Wickham h.wickham at gmail.com
Wed Jan 29 23:35:27 CET 2014


If you load plyr first, then dplyr, I think everything should work.
dplyr::summarise works similarly enough to plyr::summarise that it
shouldn't cause problems.

Hadley

On Wed, Jan 29, 2014 at 4:19 PM, Trevor Davies <davies.trevor at gmail.com> wrote:
> I think I have a hole in my understanding of how R uses packages (or at
> least how it gives functions in packages priority).  I thought I would give
> the new dplyr package a test drive this morning (which is blazingly fast
> BTW) and I've gone down the rabbit hole.
>
> The issue is that I'm unable to use both plyr and dplyr in a program that
> I'm writing.  When I initially install dplyr and I look at the summarise
> function everything works great but if I then install the plyr package the
> summarise function from dplyr is then masked with the plyr summarise
> function taking priority.  I can't seem to figure out a way to get the
> dplyr summarise to become the main function...
>
> What am I missing here? Can you not use the dplyr and plyr packages at the
> same time?
>
>
> Example:
> =========================
>> require(dplyr)
> Loading required package: 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
>
>> summarise
> function (.data, ...)
> UseMethod("summarise")
> <environment: namespace:dplyr>
>>
> =======================
> ***However, if I then install plyr I get what is below and masks the dplyr
> summarise function:**
>
>> require(plyr)
> Loading required package: plyr
> Attaching package: 'plyr'
> The following objects are masked from 'package:dplyr':
>     arrange, desc, failwith, id, mutate, summarise
>> summarise
> function (.data, ...)
> {
>     stopifnot(is.data.frame(.data) || is.list(.data) ||
> is.environment(.data))
> ....
> ...}
> <environment: namespace:plyr>
>>
> ===============
> ** Then no going back...
> require(dplyr)
>> summarise
> function (.data, ...)
> {
>     stopifnot(is.data.frame(.data) || is.list(.data) ||
> is.environment(.data))
> ....
> ...}
> <environment: namespace:plyr>
>>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
http://had.co.nz/




More information about the R-help mailing list