Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ci-misc
R-utility-belt
Commits
08a9a0ac
Commit
08a9a0ac
authored
Feb 16, 2021
by
Quentin Read
Browse files
correct bug in unnest fxn
parent
83dbd3c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
R/group_nest_dt.R
View file @
08a9a0ac
...
...
@@ -5,7 +5,7 @@
#'
#' @import data.table
#' @export
group_nest_dt
<-
function
(
dt
,
...
,
.key
=
"data"
)
{
group_nest_dt
<-
function
(
dt
,
...
,
.key
=
"data"
,
group_vars
=
NULL
)
{
stopifnot
(
is.data.table
(
dt
))
if
(
missing
(
group_vars
))
{
...
...
@@ -25,11 +25,16 @@ group_nest_dt <-function(dt, ..., .key = "data") {
#' This function was written by TS Barrett in a document available at https://osf.io/f6pxw/download.
#'
#' @export
unnest_dt
<-
function
(
dt
,
col
,
id
)
{
unnest_dt
<-
function
(
dt
,
col
,
id
,
id_vars
=
NULL
)
{
stopifnot
(
is.data.table
(
dt
))
by
<-
substitute
(
id
)
col
<-
substitute
(
unlist
(
col
,
recursive
=
FALSE
))
dt
[,
eval
(
col
),
by
=
by
]
if
(
missing
(
id_vars
))
{
by
<-
substitute
(
id
)
col
<-
substitute
(
unlist
(
col
,
recursive
=
FALSE
))
dt
[,
eval
(
col
),
by
=
eval
(
by
)]
}
else
{
col
<-
substitute
(
unlist
(
col
,
recursive
=
FALSE
))
dt
[,
eval
(
col
),
by
=
id_vars
]
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment