Skip to content

how to use "..."

26 messages · R. Michael Weylandt, Berend Hasselman, Bert Gunter +8 more

Messages 1–25 of 26

#
Dear users,

I'm trying to learn how to use the "...".

I have written a function (simplified here) that uses doBy::summaryBy():
# 'dat' is a data.frame from which the aggregation is computed
# 'vec_cat' is a integer vector defining which columns of the data.frame 
should be use on the right side of the formula
# 'stat_fun' is the function that will be run to aggregate
stat.group <- function(dat, vec_cat, stat_fun){
     require(doBy)
     df <- 
summaryBy(as.formula(paste0(".~",paste0(names(dat)[vec_cat],collapse="+"))), 
data=dat, FUN=stat_fun)
     return(df)
}

Example, works fine:
my_data <- structure(list(cat = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), varnum = 
c(-0.754816565434373,
-1.94101630973709, -0.102461836059522, -0.519952759645808, 
-1.73772800855664,
-1.13939178585609, 0.522356715260142, -0.701428514907824, 1.45197576541159,
0.0844567413828095)), .Names = c("cat", "varnum"), row.names = c(NA,
-10L), class = "data.frame")
stat.group(dat=my_data, vec_cat=1, stat_fun=mean)


Now summaryBy() has an "..." argument and I would like to use it.
For example, I would like to be able to add the trim argument to my call 
like this:
stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2)


I know I can do it using this "..." but I have no idea how to do it. 
I've tried to search for it, but a search with "..." doesn't yield 
interesting results!


Thank you in advance for your help!
Ivan
#
On Thu, Jan 17, 2013 at 2:36 PM, Ivan Calandra
<ivan.calandra at u-bourgogne.fr> wrote:
Thanks for the great working examples!

It's actually not too hard here --  just pass "..." down as if it were
an argument and let summaryBy() do the hard work of actually handling
the dots:

stat.group <- function(dat, vec_cat, stat_fun, ...){
    require(doBy)
    df <- summaryBy(as.formula(paste0(".~",paste0(names(dat)[vec_cat],collapse="+"))),
data=dat, FUN=stat_fun, ...)
    return(df)
}

Also, note that as a matter of style, you can actually clean this up a
little bit: R follows the trend of many functional languages in
automatically returning the value of the last expression evaluated:

stat.group <- function(dat, vec_cat, stat_fun, ...){
    require(doBy)
    summaryBy(as.formula(paste0(".~",paste0(names(dat)[vec_cat],collapse="+"))),
data=dat, FUN=stat_fun, ...)
}

Cheers,
Michael
#
On 17-01-2013, at 15:36, Ivan Calandra <ivan.calandra at u-bourgogne.fr> wrote:

            
This seems to work:

stat.group <- function(dat, vec_cat, stat_fun,...){
   require(doBy) 
   df <- summaryBy(as.formula(paste0(".~",paste0(names(dat)[vec_cat],collapse="+"))), data=dat, FUN=stat_fun,...)
   return(df)
}

and

stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2)

as the example for sumfun in  the help for summaryBy shows.

Berend
#
Ok, it is that simple... Actually I had tried it but messed up so that 
it didn't work.
Do you know where I can find some documentation about it?

Regarding return(), I know that it's not necessary, but when the 
function gets more complicated, I like to have it because it becomes 
clearer to me.

Thanks all!
Ivan

--
Ivan CALANDRA
Universit? de Bourgogne
UMR CNRS/uB 6282 Biog?osciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calandra at u-bourgogne.fr
http://biogeosciences.u-bourgogne.fr/calandra

Le 17/01/13 15:55, R. Michael Weylandt a ?crit :
#
Well..

On Thu, Jan 17, 2013 at 7:42 AM, Ivan Calandra
<ivan.calandra at u-bourgogne.fr> wrote:
The "R language definition" manual would be the logical place to look,
no? And sure enough, it's there!

The Introduction to R tutorial also contains info in the "writing
functions" section.

A very good, though now dated, exposition can be found in V&R's S
Programming book. Although a little care is needed due to age, it's
still my favorite.

-- Bert

  
    
#
The ellipsis object is not listed in the base help pages!

help(`+`) # this works - help on arithmetic operators
help("+") # also works
help(`...`) # fails with Error: '...' used in an incorrect context
help("...") # fails also with No documentation for '...' in specified packages and libraries: you could try '??...'


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ivan Calandra
Sent: Friday, 18 January 2013 4:43a
To: R. Michael Weylandt
Cc: R list
Subject: Re: [R] how to use "..."

Do you know where I can find some documentation about it?
#
Here's a link (on my local CRAN)...

http://cran.stat.auckland.ac.nz/doc/manuals/r-release/R-intro.html#The-three-dots-argument


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Bert Gunter
Sent: Friday, 18 January 2013 4:54a
To: ivan.calandra at u-bourgogne.fr
Cc: R list
Subject: Re: [R] how to use "..."

Well..

On Thu, Jan 17, 2013 at 7:42 AM, Ivan Calandra
<ivan.calandra at u-bourgogne.fr> wrote:
The "R language definition" manual would be the logical place to look,
no? And sure enough, it's there!

The Introduction to R tutorial also contains info in the "writing
functions" section.

A very good, though now dated, exposition can be found in V&R's S
Programming book. Although a little care is needed due to age, it's
still my favorite.

-- Bert

  
    
#
The "help" facility is applicable to functions and data sets.  It is not 
designed
or intended to give "help" with respect to R syntax (with the exception of
the basic syntax of the operators --- unary and binary --- and the 
associated
rules of precedence).

     cheers,

         Rolf Turner
On 01/18/2013 09:17 AM, Steve Taylor wrote:
#
Rolf
Perhaps the philosophy of the help system needs to change . . .
John

Sent from my iPhone
On Jan 17, 2013, at 7:11 PM, "Rolf Turner <rolf.turner at xtra.co.nz>" <rolf.turner at xtra.co.nz> wrote:

            
Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}
#
On Jan 17, 2013, at 7:00 PM, John Sorkin wrote:

            
It's probably unwise to accept any one person's claim regarding the  
"philosophy of the help system". If you have the time, energy and  
skills to construct a help page for "..." then I would inquire on the  
r-devel mailing list whether such a submission would be considered.  
After looking at the help page for "+" I think it needs at the very  
least a reference to both the ?"formula" page (since that is a core  
part of hte language) and alos suggest it should describe  the  
overloadings of "+" in the lattice and ggplot2 packages. I think it's  
too much to expect users to know that "is an S4 generic" implies a  
wide variety of potential meanings. I think those oft-used examples of  
such meanings ought to be mentioned.
#
On 13-01-17 10:00 PM, John Sorkin wrote:
And perhaps it doesn't.  Who knows?

Maybe we just need a manual on how to use the existing help system.  But 
I suspect people who won't read the existing manuals won't read that 
one, either.

Duncan Murdoch
2 days later
#
Duncan, I assume you're being facetious.  Every R user soon learns to use help() and help.search() or their equivalents.  We don't need a manual to teach that.
Then why are there help pages ?":::", ?"for", ?"NA_character_", ?".C" and ?"??" but not ?"..." ?!
#
On 13-01-20 2:28 PM, Steve Taylor wrote:
There are other parts of the help system that you don't appear to know 
about.  Run help.start() for the main index page.  help() is kind of a 
shortcut to the section labelled "Packages".  help.search() gets you to 
"Search Engine & Keywords".  There are 15 other headings to explore as well.
Those are all functions or other objects, while ... is not.  There are 
examples of topic aliases that are not objects, e.g. ?Syntax, but mostly 
Rolf is right.  Most discussion of the syntax is in the manuals.

Duncan Murdoch
#
I know about them even tho I didn't mention them.
Nevertheless, help("...") is a reasonable thing for a user to do and expect some help.
#
On 13-01-20 2:56 PM, Steve Taylor wrote:
I agree it should do something.  I think I'll have it lead to ?Reserved, 
and add pointers to the manuals from there.  I don't think the help() 
pages are right for it.

Duncan Murdoch
#
Why are the help pages not right? The ... construct is a fundamental part of the language syntax. Information about this fundamental construct should be easily available!
John

 
John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> Duncan Murdoch <murdoch.duncan at gmail.com> 1/20/2013 5:06 PM >>>
On 13-01-20 2:56 PM, Steve Taylor wrote:
I agree it should do something.  I think I'll have it lead to ?Reserved, 
and add pointers to the manuals from there.  I don't think the help() 
pages are right for it.

Duncan Murdoch

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Confidentiality Statement:
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
#
On 13-01-20 5:54 PM, John Sorkin wrote:
Yes, I agree it should be easily available.  Why does that mean it has 
to be on the help pages?  Maybe that manual on how to use the *complete* 
help system would be useful after all.

Duncan Murdoch
#
On Sun, Jan 20, 2013 at 5:54 PM, John Sorkin
<JSorkin at grecc.umaryland.edu> wrote:
This strikes me as a bit harsh. The information is easily available,
just type 'help.start()', click on the "Introduction to R" link, then
click on the "Writing your own functions" link.

I'm not saying ?'...' shouldn't do something useful, just that
complaining that the information is not easily available seems
unnecessary.
#
On Jan 20, 2013, at 11:46 AM, Duncan Murdoch wrote:

            
help.search("...")

On my Mac after a very long wait it appears I get all of the functions  
in every installed package that have a three-dots argument in their  
argument list displayed in the Usage sections. That does not seem very  
"help"-ful. I tried limiting with keyword="programming", that did not  
appear effective. I wasn't able to figure out from the  
help(help.search) page what I need to do to constrict to non-Usage  
matches yet expand to items linked from the help.start() page.

If I just search with a browser for "..." in "Introduction to R" I get  
what I consider to be useful material.
#
On 13-01-20 6:23 PM, David Winsemius wrote:
I don't think you're reading the same "help.search" help page that I'm 
reading.  help.search("...") is pretty clearly documented to do a search 
for help pages with "alias", "concept" or "title" matching the regular 
expression "...", i.e. they have three characters in one of those.  You 
should have found every single help page.

I don't see anything there that suggests it does a search through the 
usage section.  Are you just making stuff up?
Yes.  Other ways that should work, but don't:

- looking through the index to An Introduction to R.  (The index is very 
weak.)  Same for the R Language Definition.

- doing a Google search for "R ...".  Stupid Google.

Other ways that do work:

- Reading the tables of contents for An Introduction to R, or the R 
Language Definition.

- Reading those manuals.

- ?"..." in R-devel, after I commit the changes I described.

- Searching with grep through the source files named *.Rd or *.texi. 
(For this you need to have the source installed.)

I do think the help system is too fragmented, but I also believe it is 
better than it used to be.  I am sure that people would make false 
claims about it regardless of any improvements, and other people would 
complain about any changes, so it's not a priority for me to work on it 
any more.

Duncan Murdoch
#
On Jan 20, 2013, at 3:52 PM, Duncan Murdoch wrote:

            
Apparently. I was constructing a theory to explain why my search was  
taking so long and returning so many pages. With your clarification  
above I tried a somewhat more successful search. I clearly missed  
reading the Description paragraph. New strategy:

help.search("\\.\\.\\.")

There are only 15 or so hits (could be more or less depending on the  
composition of the library packages)  and among them is 'dotsMethods'.  
That looks like a useful page for this topic.  The number of hits  
would only be half as large if the author of the "labeling" package  
had not put "..." at the end of 8 of his help page titles.

Sorry for the noise.

-- David.
David Winsemius, MD
Alameda, CA, USA
#
Since this topic was mine originally, I supposed I can give my opinion, 
for what it's worth!

First, it is true that there is some help in the manuals. The problem 
with these manuals (or at least, my problem) is that there were much too 
complicated when I started to learn R. Then I got used to other ways of 
looking for help, especially ? or help(). Now that I understand more 
about R, I should think about the manuals again.
Because of this, if "..." should not be included in a help page, I 
believe that ?"..." should at least lead to the relevant documentation.

Now to the documentation itself. I find this "..." very strange; it is 
not intuitive at all for me. And the explanations in the manuals 
(Introduction to R and R language definition) are very short, without 
any details and real practical examples (please correct me if I missed 
something). This construct is very easy to use when it is implemented in 
some functions, but somehow I don't feel at ease when using it to write 
my own functions; I cannot predict how it should work, I can only try 
and see what happens. Actually I feel that it is very easy, at least in 
most cases; but I cannot be sure of it.

Hope this helps to make things even better!
And thank you again for the original problem :)
Ivan

--
Ivan CALANDRA
Universit? de Bourgogne
UMR CNRS/uB 6282 Biog?osciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calandra at u-bourgogne.fr
http://biogeosciences.u-bourgogne.fr/calandra

Le 21/01/13 03:41, David Winsemius a ?crit :
9 days later
#
There is now a blog post that attempts to
answer the question in the subject line:

http://www.burns-stat.com/the-three-dots-construct-in-r/

Pat
On 17/01/2013 14:36, Ivan Calandra wrote:

  
    
#
Because R can be interactive, I find that a little exploring through
the use of strategically placed browser() calls (?browser if you are
unfamiliar with this handy debugging tool) is often the fastest way to
solve little R puzzles like this.

For example, try this (in an R GUI):

f2 <- function(y,...){ browser(); list(...) }
f1 <- function(x,...){ browser(); f2(x,...) }

Now at the command line:
## In the f1 browser  do ls() to see what's in the f1 environment
## and then do list(...) to see what's in the dots argument
## then issue the browser command  c  to continue
## and do the same in the f2 browser .

## then try:
I think this help give you a better idea of what's going on (or
totally confuse?!).

-- Bert
On Wed, Jan 30, 2013 at 8:15 AM, Patrick Burns <pburns at pburns.seanet.com> wrote:

  
    
#
Dear Patrick,

This is indeed a nice post to address the three dot issues.
It is definitely much clearer to me now

Thanks!
Ivan

--
Ivan CALANDRA
Universit? de Bourgogne
UMR CNRS/uB 6282 Biog?osciences
6 Boulevard Gabriel
21000 Dijon, FRANCE
+33(0)3.80.39.63.06
ivan.calandra at u-bourgogne.fr
http://biogeosciences.u-bourgogne.fr/calandra

Le 30/01/13 17:15, Patrick Burns a ?crit :