Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R-Forge #1302] Document and test type "function" in columns #518

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 3 comments
Closed
Assignees
Milestone

Comments

@arunsrinivasan
Copy link
Member

Submitted by: Matt Dowle; Assigned to: Nobody; R-Forge link

e.g.
DT = data.table(ID=1:10,A=rnorm(10),B=rnorm(10),fn=c(min,max))
DT[,fn(A,B),by=ID]

Idea as a result of Damian Betebenner's post to datatable-help on 26 Feb "data.table by versus apply"

@MichaelChirico
Copy link
Member

Well, this works:

DT[, fn[[1]](A, B), by = ID]
#     ID         V1
#  1:  1 -0.4469455
#  2:  2  0.1287365
#  3:  3  0.7078934
#  4:  4  0.2993082
#  5:  5 -1.9502759
#  6:  6  0.1837118
#  7:  7 -1.3879306
#  8:  8  2.7514174
#  9:  9 -2.1987866
# 10: 10  0.3488647

The new class option to print is handy here:

print(DT, class = TRUE)
#        ID          A          B         fn
#     <int>      <num>      <num>     <list>
#  1:     1  0.4263173 -0.4469455 <function>
#  2:     2 -0.6330037  0.1287365 <function>
#  3:     3  0.7078934  0.8974549 <function>
#  4:     4  0.2993082 -0.7105668 <function>
#  5:     5 -0.1777093 -1.9502759 <function>
#  6:     6 -0.9460802  0.1837118 <function>
#  7:     7  0.9298305 -1.3879306 <function>
#  8:     8  2.7514174 -1.9198391 <function>
#  9:     9  0.6609640 -2.1987866 <function>
# 10:    10 -0.5695234  0.3488647 <function>

So functions are currently being stored as lists, and can be extracted like list items.

Not sure if this FR is after additional functionality...

@jangorecki
Copy link
Member

I use functions in a list column in Rbitcoin pkg which is on CRAN. It works well, not sure if we need to support function column type explicitly. Base c(min,max) returns a list, so better to stay with the list then.
Having that in mind this issue seems to be in fact a FR to not need for [[1L]] to use function, which is duplicate of #582. Re-open if you not agree.

@jangorecki
Copy link
Member

I will reopen as the issue asks for documenting the usage of function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants