[R] Passing parameters in a user defined function to another function using ...

2013-11-18 Thread Lopez, Dan
Hi R Experts,

How do you get the ... to work in a user-defined function such as the one I 
have below?
For example if I want to pass replace=TRUE to the sample function.

# This is a sample function that generates x rows of z numbers out of y. 
Basically a lottery style data set.

mynumbs-function(x,y,z=5,...){
  #x should be a scalar indicating number of rows
  #y  z are passed to sample function
  #in the future will add option to output as data.frame instead of matrix

  numbs-sort(sample(y,z))
  for (i in 1:(x-1))
numbs-rbind(numbs,sort(sample(y,z)))
  print(numbs)
}

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Passing parameters in a user defined function to another function using ...

2013-11-18 Thread Lopez, Dan
Thanks Ben.

I feel really dumb. I did enter '...' in my sample function in another version 
of this function. But I just realized I had only done it for the second 
occurrence of the sample function and not the first.

Dan


-Original Message-
From: Ben Tupper [mailto:btup...@bigelow.org] 
Sent: Monday, November 18, 2013 6:00 PM
To: Lopez, Dan
Cc: R help (r-help@r-project.org)
Subject: Re: [R] Passing parameters in a user defined function to another 
function using ...

Hi,

It's easy, just carry the arguments in '...' forward to where you expect to 
pass them along.


mynumbs-function(x,y,z=5,...){
 numbs-sort(sample(y,z, ...))
 for (i in 1:(x-1))
   numbs-rbind(numbs,sort(sample(y,z, ...)))
 print(numbs)
}

Cheers,
Ben


On Nov 18, 2013, at 8:52 PM, Lopez, Dan lopez...@llnl.gov wrote:

 Hi R Experts,
 
 How do you get the ... to work in a user-defined function such as the one I 
 have below?
 For example if I want to pass replace=TRUE to the sample function.
 
 # This is a sample function that generates x rows of z numbers out of y. 
 Basically a lottery style data set.
 
 mynumbs-function(x,y,z=5,...){
  #x should be a scalar indicating number of rows  #y  z are passed to 
 sample function  #in the future will add option to output as 
 data.frame instead of matrix
 
  numbs-sort(sample(y,z))
  for (i in 1:(x-1))
numbs-rbind(numbs,sort(sample(y,z)))
  print(numbs)
 }
 
   [[alternative HTML version deleted]]
 
 __
 R-help@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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@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.


Re: [R] Passing parameters in a user defined function to another function using ...

2013-11-18 Thread Richard M. Heiberger
numbs - rbind(numbs, sort(sample(y, z, ... )))

See
?Reserved
which sends you to 'Introduction to R'

Rich

On Mon, Nov 18, 2013 at 8:52 PM, Lopez, Dan lopez...@llnl.gov wrote:
 Hi R Experts,

 How do you get the ... to work in a user-defined function such as the one I 
 have below?
 For example if I want to pass replace=TRUE to the sample function.

 # This is a sample function that generates x rows of z numbers out of y. 
 Basically a lottery style data set.

 mynumbs-function(x,y,z=5,...){
   #x should be a scalar indicating number of rows
   #y  z are passed to sample function
   #in the future will add option to output as data.frame instead of matrix

   numbs-sort(sample(y,z))
   for (i in 1:(x-1))
 numbs-rbind(numbs,sort(sample(y,z)))
   print(numbs)
 }

 [[alternative HTML version deleted]]

 __
 R-help@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.

__
R-help@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.


Re: [R] Passing parameters in a user defined function to another function using ...

2013-11-18 Thread Ben Tupper
Hi,

It's easy, just carry the arguments in '…' forward to where you expect to pass 
them along.


mynumbs-function(x,y,z=5,...){
 numbs-sort(sample(y,z, ...))
 for (i in 1:(x-1))
   numbs-rbind(numbs,sort(sample(y,z, ...)))
 print(numbs)
}

Cheers,
Ben


On Nov 18, 2013, at 8:52 PM, Lopez, Dan lopez...@llnl.gov wrote:

 Hi R Experts,
 
 How do you get the ... to work in a user-defined function such as the one I 
 have below?
 For example if I want to pass replace=TRUE to the sample function.
 
 # This is a sample function that generates x rows of z numbers out of y. 
 Basically a lottery style data set.
 
 mynumbs-function(x,y,z=5,...){
  #x should be a scalar indicating number of rows
  #y  z are passed to sample function
  #in the future will add option to output as data.frame instead of matrix
 
  numbs-sort(sample(y,z))
  for (i in 1:(x-1))
numbs-rbind(numbs,sort(sample(y,z)))
  print(numbs)
 }
 
   [[alternative HTML version deleted]]
 
 __
 R-help@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.

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

__
R-help@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.