Description Usage Arguments Details Value How to use
View source: R/data.frame__to__grouped_df.R
Given an S3 method for class data.frame
, create an S3 method
for class grouped_df
for the same generic function.
1 |
fun |
a function; this must be an S3 method for class |
This is a utility function for writing packages. Functions that modify data frames by replacing or adding columns may fail on grouped data frames so the class will require a dedicated method. This is a generalized constructor of such methods.
In all cases the original call to foo
is captured with match.call
and reconstructed into a call to the data.frame
method.
Grouping variables are isolated as a list, and the first argument of foo
,
which must be named x
, is split into a list with split
, using the
list of grouping variables as splitting factors. Empty levels are dropped.
The list is then passed to lapply
, with the call to the data.frame
method
as FUN
. The result is reconstituted into a single data.frame
with
unsplit
, again dropping empty levels.
a function: a method for class grouped_df
(from package dplyr
)
When creating an .R file for generic foo
and its S3 methods,
simply add another entry where foo.grouped_df
is defined as the result of
data.frame__to__grouped_df
acting on foo.data.frame
.
Copy the following roxygen
tag before the function definition
to have it show up nicely in the documentation file:
@describeIn foo see \code{\link[metamethods]{data.frame__to__grouped_df}}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.