Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using colwise() within an S3 method

Tags:

r

plyr

I have a function shift defined as:

require(plyr)
shift <- function(x,...) {
    UseMethod("shift",x)
}
shift.default <- function(x,n=1,wrap=TRUE,pad=FALSE,...) {
    # innards
    return(0)
}
shift.data.frame <- colwise(shift.default)

It works just fine, until I put it in a package and try R CMD check. Then I get a warning while checking S3 generic/method consistency. It reports that shift.data.frame and shift don't agree:

shift(x,...)
shift.data.frame(df,...)

I assume this results from x and df not matching. Any convenient way to fix this?

like image 517
Ari B. Friedman Avatar asked Sep 24 '26 13:09

Ari B. Friedman


1 Answers

Does something like this work?

shift.data.frame <- function(x, ...) {
  colwiseShift <- colwise(shift.default)
  colwiseShift(x, ...)
}
like image 199
GSee Avatar answered Sep 27 '26 19:09

GSee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!