Hi, I was wondering what would be the best way to check if the three dots argument contains any arguments (i.e. does ... contain any arguments or not? ) #Example test = function(x,y, ...) { #Wanted R-Code # if(empty(...)) # do some calculation plot(x,y,...) } Thanks Thomas Roth
Try dots <- list(...) if (length(dots) == 0) { ## do something } On Thu, Jul 16, 2009 at 6:46 AM, Thomas Roth (geb. Kaliwe)<hamstersquats at web.de> wrote:> Hi, > > I was wondering what would be the best way to check if the three dots > argument contains any arguments (i.e. does ... contain any arguments or not? > ) > > #Example > > test = function(x,y, ...) > { > ? #Wanted R-Code > ? # if(empty(...)) > ? # ? ?do some calculation > > > ? plot(x,y,...) > > } > > Thanks > > Thomas Roth > > ______________________________________________ > 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. >
one way is: test <- function(x, y, ...) { dots <- list(...) if (length(dots)) cat("\nnon-empty\n") else cat("\nempty\n") } test(1, 1) test(1, 1, 1) I hope it helps. Best, Dimitris Thomas Roth (geb. Kaliwe) wrote:> Hi, > > I was wondering what would be the best way to check if the three dots > argument contains any arguments (i.e. does ... contain any arguments or > not? ) > > #Example > > test = function(x,y, ...) > { > #Wanted R-Code > # if(empty(...)) > # do some calculation > > > plot(x,y,...) > > } > > Thanks > > Thomas Roth > > ______________________________________________ > 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. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
Thank you both. Thomas Dimitris Rizopoulos schrieb:> one way is: > > test <- function(x, y, ...) { > dots <- list(...) > if (length(dots)) cat("\nnon-empty\n") else cat("\nempty\n") > } > > test(1, 1) > test(1, 1, 1) > > > I hope it helps. > > Best, > Dimitris > > > Thomas Roth (geb. Kaliwe) wrote: >> Hi, >> >> I was wondering what would be the best way to check if the three dots >> argument contains any arguments (i.e. does ... contain any arguments >> or not? ) >> >> #Example >> >> test = function(x,y, ...) >> { >> #Wanted R-Code >> # if(empty(...)) >> # do some calculation >> >> >> plot(x,y,...) >> >> } >> >> Thanks >> >> Thomas Roth >> >> ______________________________________________ >> 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. >> >