tao.hong tao.hong - 3 months ago 18
R Question

Properly reference ddply in a package

I created a package which heavily uses

dplyr
, in the meanwhile, this package needs to include a different function which relies on
ddply
from
plyr
package. Originally, I directly used
@import plyr
, but it caused naming conflicts which broke my other functions.

So I guess my only solution is to include necessary functions. Thus I added
@importFrom plyr ddply ldply llply
since
ldply llply
is used in
ddply
. However, it failed...

Some code sample



DESCRIPTION : I include
dplyr
and
plyr
under
Imports


Package: My ProdComp
Type: Package
Imports:
dplyr, plyr


NAMESPACE (generated by ROXYGEN2)

import(dplyr)
importFrom(plyr,ddply)
importFrom(plyr,ldply)
importFrom(plyr,llply)


Acturally script

#' @importFrom plyr ddply ldply llply
#'
#' @import dplyr
#'
#' @export

final_table <- ddply(product_type_subset,.(general_category, product_type, cas), summarise, Value = toString(maximum_weight_fraction[!is.na(maximum_weight_fraction)]))


Error message

Error in as.quoted(.variables) : could not find function "."


So any suggestions on how to make it right?

Answer

. is in plyr, not dplyr.

> dplyr::.
Error: '.' is not an exported object from 'namespace:dplyr'
> plyr::.
function (..., .env = parent.frame()) 
{
    structure(as.list(match.call()[-1]), env = .env, class = "quoted")
}
<environment: namespace:plyr>

So just import it from plyr along with the other functions.